You are here

How to Include Command Line Parameters?

17 posts / 0 new
Last post
jwinter
Offline
Last seen: 4 years 6 months ago
Joined: 2008-06-02 00:40
How to Include Command Line Parameters?

I am trying to add Skype to my portable apps and cannot seem to find an easy way to have it kick-off with a simple click to a portable apps menu. Skype offers portability by using command line parameters: "Skype.exe /datapath:data /removable". But how to get the command line parameters included as part of the command!?

Some things I have tried and some of their problems are:
1)Create a batch file called .bat or .cmd - but then it isn't listed in the portable apps menu (besides which having a command window flash up looks ugly and unprofessional).
2)Try calling the batch file .exe - then it is listed but of course it doesn't work!
3)Try creating a "short cut" with command line parameters added in the properties and which is then called .exe - but for some reason this doesn't list in the menu! (it also seems to lock the command to a particular drive letter making it unportable).
4)Tried adding it as a custom shortcut in the GeekMenu's "Advanced Options" but while it finds the .exe it seems to ignore the parameters following it.
5)Tried adding these command line arguments to SmithTech's Portable Menu in the "Argument" field - but it didn't seem to work, and seeing that there is another field to allow entry of an "Exit Argument" I realize I probably don't know what I am doing because I can't imagine what is meant by an "exit" argument!

Surely there is some way to achieve this simple objective is there not?

Should one of the above approaches have worked - indicating I have something else out of whack?

Please educate a poor noob!

wk
wk's picture
Offline
Last seen: 9 months 3 weeks ago
Joined: 2007-09-05 12:31
use a bat to exe converter

like that from here http://www.abyssmedia.com/quickbfc/index.shtml
some AV Scanners might give trojan alerts but, often, they´re false positive

"Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis .." Friday Next -
"May The Schwartz be with You!" Yogurt the Yoda

Ed_P
Offline
Last seen: 5 years 6 months ago
Joined: 2007-02-19 09:09
Not at $74.95!!

Bat2Exe does the same thing and is free.
http://www.softpedia.com/get/Programming/Coding-languages-Compilers/Bat2...

To minimize the command prompt window you can add something like
@title PAM menu
@echo off &MODE CON COLS=20 LINES=4
cd MyAppFiles
start /min myapp.exe %1

to the top of the script. (Oops I got carried away, that's the whole script.)

And if you use Bat_to_Exe_converter it allows for the app to be ghosted. It is free also.
http://www.f2ko.de/English/b2e/download.php

Both output exes may create the same false AV positives and Windows Defender alerts noted above. I believe the characters UPX in the exes trigger the false alerts and changing them to something like UPY with a hexeditor stops the alerts. But it's been awhile since I did it so I don't remember.

Ed

wk
wk's picture
Offline
Last seen: 9 months 3 weeks ago
Joined: 2007-09-05 12:31
I agree absolutely, but it´s free for a testing period

I agree absolutely, but it´s free for a testing period, and I had some true alerts with so called free bat2exe, so for just one or to bat2exe it works fine and reliable...

"Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis .." Friday Next -
"May The Schwartz be with You!" Yogurt the Yoda

dark_yux
Offline
Last seen: 10 years 2 months ago
Joined: 2007-10-23 11:23
Try a diffrent Menu

P Start allows you to assign .bat files to the menu and no Trojan alerts.

self.path = path if self.path == None else self.path

Terry Young
Offline
Last seen: 9 years 4 months ago
Joined: 2008-06-04 08:36
AutoIt (FREE), 2 lines of code and tool included for conversion.

Here it is: AutoIt.

In good hands, it can be a powerful automation tool, not just for converting batch files to exe (in case you are wondering). It includes a Aut2exe.exe, which does the conversion.

Steps below:

Download AutoIt (duh)

Open a text file, use the following code

#include <Process.au3>
$rc = _RunDos("start Skype.exe /datapath:""Data"" /removable")

Use double quotes to wrap the data path, in case it consists of spaces.

Save the text file with the au3 extension (not txt).

Use the Aut2exe.exe tool (in the Aut2exe folder, obviously) to convert it to an exe. Its interface is quite self explanatory.

Put your converted exe (I named it "Run Skype.exe") to the same path as the original Skype.exe

And since I see you're using GeekMenu as well, you can hide the original Skype.exe

Clean results. No left-alone command prompt windows hanging around, in case you ask before trying.

:: finale ::

Once you are familiar with AutoIt (and start digging into AutoIt's sea of exaxmples), I guess you will sense that the possibilities are endless. For example, I have a whole bunch of batch files that do lots of logging and other diagnostics in DOS, and I simply convert this to run my main batch:

#include <Process.au3>
$rc = _RunDos("start main.bat")

...then a whole bunch of spaghetti code starts whippin'...

Another example of including command line parameters which I have is to run Internet Explorer without loading the Add-ons, using the -extoff parameter. AutoIt code ahead:

#include <Process.au3>
$rc = _RunDos("cd ""%ProgramFiles%\Internet Explorer""")
$rc = _RunDos("start iexplore.exe -extoff")

Or convert an AutoIt script to one single exe in order to launch multiple portable apps in one click (with or without command line parameters), or even geekier, modify autorun.inf to startup your AutoIt script (exe) instead of the portable menu, which will in turn launch both the portable apps menu and the routine apps you may use. Well, you know the drill, so I'd stop here and leave the imaginations to you. Oh, and I also keep an unzipped version of AutoIt in my USB Thumb, an essential to my collection.

Cheers. Tell me if it works for you.

I need coffee...

ZachHudock
ZachHudock's picture
Offline
Last seen: 1 year 3 months ago
Developer
Joined: 2006-12-06 18:07
If he already has the batch

If he already has the batch files written, using a simple bat2exe program is just fine. Learning another scripting language seems a bit much, but if the user is willing to do this, I'd recommend AutoHotkey over AutoIt. AHK has fewer false positives from anti-virus software, and AHK is fully open source, while AutoIt became closed source.

The developer formerly known as ZGitRDun8705

Terry Young
Offline
Last seen: 9 years 4 months ago
Joined: 2008-06-04 08:36
Good point

Thanks for the info about the false positives (googled it after you mentioned it), and AHK (yes, apparently it is currently under GNU General Public License).

In case he considers accepting AutoIt/AHK, what he needs to accomplish running portable skype was just those two lines. I offered it so that he can choose to skip the learning. The learning curve is just another door for more possibilities, while bat2exe may limit itself to batch only. He does sound a bit willing, since he mentioned multiple trials-and-errors, efforts shown.

Rejecting bat2exe wasn't my intention. All these are alternatives. I chose AutoIt instead, because I had plans... big plans.

Anyway, thanks again for recommending AHK, yes, I would recommend that (and switch to that) too, if open source is a concern (and if false positives are not a concern).

I need coffee...

ZachHudock
ZachHudock's picture
Offline
Last seen: 1 year 3 months ago
Developer
Joined: 2006-12-06 18:07
Not a problem, glad to have

Not a problem, glad to have pointed you to an alternative.

This site's main focus is OpenSource. It's not necessarily a concern, but if there is an open source alternative to an app somebody requests/recommends, we typically make mention of that OSS alternative as well.

The developer formerly known as ZGitRDun8705

Terry Young
Offline
Last seen: 9 years 4 months ago
Joined: 2008-06-04 08:36
Steps for using AutoHotkey instead

mmm.... OSS, ll take note of that. In case he is having problems with (or wants to skip learning) AHK. Here's how.

Save the following text as a file with an .ahk extension

Run Skype.exe /datapath:"Data" /removable

If you run the ahk file directly with AutoHotkey.exe (in case one wonders what the heck it does), it may complain about missing file. No worries, ignore it, we don't even need it for this task, since we know we are going to compile it into exe and to put it in the same directory as the original Skype.exe

Use Ahk2Exe.exe (what is really needed for this task) that came with AHK to compile as an exe.

The rest is pretty much the same as what I've mentioned earlier.

I need coffee...

Hooonza
Offline
Last seen: 15 years 9 months ago
Joined: 2008-07-08 17:38
I have found a nice way to

I have found a nice way to make skype portable. This tip suggests to copy "skype.exe" to a directory of USB a and make a directory "data" i the previous directory. Do it. Use PStart to make a portable start menu. There you can add a menu item named "Skype Portable" where you can set command line parameters to run an application. There you write "/datapath:"Data" /removable". That´s it!

Hooonza (OpenPGP ID: 0x5C314D52)

Nickwiz
Offline
Last seen: 15 years 7 months ago
Joined: 2008-09-11 20:39
Skype Bat Alternative


Came across a machine where i was denied bat execution.
Wrote this "one line c prog" Blum - if any find it usefull.

  • Purpose: to launch skype portable from USB stick.
    - On systems where you can run exe files but not bat files,
    run commands, .. and similar.
  • Added some icons and svg's as well...
    eg: http://img359.imageshack.us/my.php?image=logov2fq9.png
  • Source: ShellExecute(GetDesktopWindow(), "open", "./bin/Skype.exe", "/datapath:\"Data\" /removable", NULL, SW_SHOWNORMAL);

http://www.fileshack.us/get_file.php?id=238220&file=SkypePortable.exe (sorry don't have any better alternative at the moment)

MD5 Sum: 88d19cb8dd9cafe8e53498843f309870

This is *only* a caller.
m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
CreateProcess is about 0.1sec

CreateProcess is about 0.1sec faster than ShellExecute.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

flyingstar16
Offline
Last seen: 11 years 9 months ago
Joined: 2008-09-12 09:12
I've created an app launcher

I've created an app launcher and modified files' path in order to display only "Skype, Portable Edition" in PA Launcher.

  • PortableApps (root)
    • Skype (Folder)
      • Data (Folder)
      • Skype.exe (Skype's original exe)
    • SkypePortable.exe (My launcher)

So with this C++ code

/*
Skype(R) Launcher released under GPL License
Author: flyingstar16
*/

#define _WIN32_WINNT 0x0500
#include
#include
int main()
{
HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );

std::cout
I've created "SkypePortable.exe", that launches Skype.exe with "/datapath:Data /removable".

Here it is (with Skype's Icon and comments :P): SkypePortable.exe

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
1. Use WinMain instead of

1. Use WinMain instead of main in order to get rid of the console window.
2. Parsing own command line parameters is useful. And when you do, it's best to use Unicode, it works faster and will surely send command line correctly, without double translation.
3. system("command") == CreateProcess("cmd.exe /c command"); When command is a file name, cmd.exe calls ShellExecuteEx("command"). That's even slower than calling ShellExecute / ShellExecuteEx directly.
4.
#include
#include
??
5. I guess that use of Skype icon is illegal.
6. It's good to check what functions return i.e. to warn use that Skype.exe was not found
7. It doesn't work when current directory is other than program's directory.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

flyingstar16
Offline
Last seen: 11 years 9 months ago
Joined: 2008-09-12 09:12
Ok, I'm new at C++, I had to

Ok, I'm new at C++, I had to use guides and tips I found on the net, so:
1. I don't know how to use WinMain instead of main;
2. I don't know how to use Unicode (instead of what? O_o)
3. Er...
4 Drupal cut brackets, it was

#include <windows.h>
#include <iostream>

5. I'm not sure about it: https://developer.skype.com/Download/Licensing/SCL says that I must use it with Skype APIs, but using it with Skype is the same, IMHO (or not?)
6. It'll be, if I'm able to °-° (I've built it with Dev C++ and with my little little knowledge of C++.. give me 1 year and after some college courses maybe I'll know how to do it better xD)
7. I've tried to make it work and it works perfectly on my Sandisk Cruzer micro 4GB on Windows Vista, with the folder scheme I have described in my comment..

m2
Offline
Last seen: 13 years 2 months ago
Joined: 2006-12-12 12:00
1.

1. http://msdn.microsoft.com/en-us/library/ms633559.aspx

int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR argsLine,
    int nCmdShow)
{
    // your code
    // you don't need things like ShowWindow anymore
    return 0;
}

2. OK, not too much at the time, stay with ANSI for now. Smile
3. http://msdn.microsoft.com/en-us/library/ms682425.aspx

STARTUPINFO si;
GetStartupInfo(&si);
    
PROCESS_INFORMATION pi;

if(CreateProcess(NULL,
    "Skype\\Skype.exe /datapath:Data /removable",
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &si,
    &pi))
{
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}
else
{
    MessageBox(0,"Can't start Skype!","Error!",0);
}

4. OK.
5. Seems OK.
6. You have an example above. While it's not the best way of doing this, it's the simplest and good enough.
7. It's not about directory structure. Skype\Skype.exe means actually current_directory\Skype\Skype.exe. When you start your program by double click in Explorer, current directory is always set you your program directory, so it works. It's not always (still usually though) with shortcuts, .bats and other programs that start your program. To ensure that current_directory\Skype\Skype.exe == your_directory\Skype\Skype.exe, you should call SetCurrentDirectory with your executable directory...which can be obtained using GetModuleFileName. This needs HMODULE as a parameter. You can get it by calling GetModuleHandle(NULL).
So the pseudocode would be:

string myPath = GetModuleFileName(GetModuleHandle(NULL));
CutAfterLastBackslash(myPath);
SetCurrentDirectory(myPath.c_str());

Don't jump on it until you feel you're ready. Have good base first. Smile
Good luck, it's really nice to see sb. learning C++ here. Smile

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

Log in or register to post comments