Archive: executing dos commands


executing dos commands
i have a problem with executing native dos shell comands like "echo"

"echo text > $INSTDIR\location.txt" written in the shell/command line of windows results in the creation of a file that contains "text"

while trying to have similar result from with a nsis script i tried

Exec "echo $INSTDIR > $INSTDIR\location.txt"

Exec '"echo" $INSTDIR > $INSTDIR\location.txt'

even

Exec '"command.com" echo $INSTDIR > $INSTDIR\location.txt'

and the file is never created

can anyone help ?


if all you're trying to do is put the instdir variable into a file, try using the file functions.

FileOpen $0 "filename" w
FileWrite $0 "$INSTDIR"
FileClose $0

-Tim


can anyone help me with this, i didnt want to make a topic with almost the same name

im making a script to run cmd.exe then runas.exe with some parameters, the problem is, the runas.exe program asks for the admin password, how can to write the pass in the script and hit enter?


You'll have to use Windows API (System plug-in) to similate key events (SendKeys).


Can't him do that using SendMessage, Joost? Or that is the only one way to do that?


Joost, please explane how "to similate key events (SendKeys)". User has handle for running DOS (console) process, how to send key?

BTW, with Windows API it is possible to create DOS application (run runas.exe with parameters) with redirected IO using pipes, this case application waits for WriteFile() output (with password, for example), such plug-in might be usefull.


If you can get it to work using the console you can always call the console with a command using Exec.

I have no time to write complete Windows API examples, sorry.


Sorry, my English is very very poor.

If your "runas.exe" is a dos program and it totally only need input this 2 things just like this:


Username:
Password:

then you can make a text file (ex: QUOTE.TXT) with 3 line like this:
line 1:somebody this is username string
line 2:12345678 this is password string
line 3: this line have nothing here. You must keep this blank line here for input [Enter] key
after that, use a I/O redirect to input those for you.


...
exec '"$Sysdir\cmd.exe" "fullpath\runas.exe" < "fullpath\Quote.txt"'
...

s793016

I/O redirection with < and > works fine on Linux, and on some of Wins too, but unfortunately, not on all :-(( This is why I had to to use correct rediriction with pipes in my applications.


the way to exec a dos command like echo:

cmd.exe /K echo Hello World

/C - Carries out the command specified by string and then terminates
/K - Carries out the command specified by string but remains

and u would have to use command.com on 9x ofcourse


Originally posted by Takhir
s793016

I/O redirection with < and > works fine on Linux, and on some of Wins too, but unfortunately, not on all :-(( This is why I had to to use correct rediriction with pipes in my applications.
can you explain to me how you did it? please.. =)

Originally posted by Anders
the way to exec a dos command like echo:

cmd.exe /K echo Hello World

/C - Carries out the command specified by string and then terminates
/K - Carries out the command specified by string but remains

and u would have to use command.com on 9x ofcourse
it doenst work

tried

runas /user:localhost\user "program" /K password

i/o redirect sample
a bit of code.

((pthreadParams)ptp)->rq(hInputWrite, hOutputRead, ((pthreadParams)ptp)->param);

is a call to program, which handles child process i/o (like lgOutput() sub).
More info u can find in MSDN.


Re: i/o redirect sample

Originally posted by Takhir
a bit of code.

((pthreadParams)ptp)->rq(hInputWrite, hOutputRead, ((pthreadParams)ptp)->param);

is a call to program, which handles child process i/o (like lgOutput() sub).
More info u can find in MSDN.
i wish i knew more... i really cant understand your program..

isnt there a easier way to do what i want? how that API thing works?

If you want to use redirection, these examples from the "Help w/ mysql script" thread might help:

http://forums.winamp.com/showthread....65#post1300365

http://forums.winamp.com/showthread....10#post1300410

http://forums.winamp.com/showthread....64#post1302664


Drako12: Please note - C code is attached to previous post as io.txt file.
And BTW instead of using FileOpen, Write, Close (treehousetim post) it might be better to include password file to package and to use it from tmp folder (don't copy to $INSTALL).


Quote:


i tried with a file something like this

runas /user:localhost\user "program" < C:\x.txt


where x has the password
but i get an error , it says "RUNAS cannot accept this input" or something like that

Originally posted by pengyou
If you want to use redirection, these examples from the "Help w/ mysql script" thread might help:

http://forums.winamp.com/showthread....65#post1300365

http://forums.winamp.com/showthread....10#post1300410

http://forums.winamp.com/showthread....64#post1302664


Quote:


i understand C, but i cant understand what you program does =/

Originally posted by Takhir
Drako12: Please note - C code is attached to previous post as io.txt file.
And BTW instead of using FileOpen, Write, Close (treehousetim post) it might be better to include password file to package and to use it from tmp folder (don't copy to $INSTALL).


If you only need to ask for a password from the DOS api take a look here, its works fine:

http://www.ericphelps.com/batch/userin/index.htm

Now my next question, I use Exec for running a DOS command, is it somehow possible to avoid that the DOS box opens and closes? thanxs

cheers,
alej


NSIS ExecShell (as I can see in exec.c) is implemented using ShellExecute API call. ShellExecute supports more "show modes", then you can see in NSIS docs, try one of them: SW_HIDE (0)


Cool it works! But in which docu does this mode appear, not on the NSIS User Manual. Are there any other docus? thanxs!

cheers,
alej


MSDN knowledge base :)

http://msdn.microsoft.com/library/de...ellexecute.asp

and MS VS WINUSER.H


ups did not know that it was microsofts shellexecute! thanxs!


I had few free minutes and wrote my first NSIS plugin for console applications :)
http://forums.winamp.com/showthread....hreadid=181442


Is it possible to execute dos commands using ExecShell? I tried the following:

ExecShell open "net use ..." SW_HIDE
and
ExecShell open "cmd.exe net use ..." SW_HIDE

it doesn't give any error but it doesn't execute it. Exec works fine but I don't want that the dos box appears upon execution and the 'hide' option is not available for exec right? thanxs


System::Call 'kernel32.dll::WinExec(t "net use...", i 0) i.r0'

http://forums.winamp.com/showthread....hreadid=182096


Voilá!