- NSIS Discussion
- executing dos commands
Archive: executing dos commands
mancini
14th May 2004 19:52 UTC
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 ?
treehousetim
14th May 2004 20:01 UTC
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
Drako12
14th May 2004 20:56 UTC
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?
Joost Verburg
14th May 2004 21:16 UTC
You'll have to use Windows API (System plug-in) to similate key events (SendKeys).
deguix
15th May 2004 03:04 UTC
Can't him do that using SendMessage, Joost? Or that is the only one way to do that?
Takhir
17th May 2004 13:36 UTC
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.
Joost Verburg
17th May 2004 14:03 UTC
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.
s793016
17th May 2004 15:35 UTC
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"'
...
    
    
      Takhir
      17th May 2004 17:08 UTC
      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.
     
    
    
      Anders
      17th May 2004 18:18 UTC
      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
     
    
    
      Drako12
      17th May 2004 18:23 UTC
      
      
        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.. =)
    
 
    
    
      Drako12
      17th May 2004 18:52 UTC
      
      
        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
    
 
    
    
      Takhir
      17th May 2004 19:36 UTC
      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.
     
    
    
      Drako12
      17th May 2004 20:11 UTC
      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?
    
 
    
    
    
    
      Takhir
      18th May 2004 07:02 UTC
      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).
     
    
    
      Drako12
      18th May 2004 18:25 UTC
      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
      
      
        Drako12
        18th May 2004 18:33 UTC
        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).
 
 | 
        
        
          almoes
          26th May 2004 14:48 UTC
          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
         
        
        
          Takhir
          26th May 2004 17:12 UTC
          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)
         
        
        
          almoes
          27th May 2004 12:45 UTC
          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
         
        
        
          Takhir
          27th May 2004 13:02 UTC
          MSDN knowledge base :)
          
          http://msdn.microsoft.com/library/de...ellexecute.asp
          
          and MS VS WINUSER.H
         
        
        
          almoes
          27th May 2004 13:04 UTC
          ups did not know that it was microsofts shellexecute! thanxs!
         
        
        
          Takhir
          28th May 2004 10:48 UTC
          I had few free minutes and wrote my first NSIS plugin for console applications :)
          http://forums.winamp.com/showthread....hreadid=181442
         
        
        
          almoes
          4th June 2004 15:49 UTC
          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
         
        
        
          Takhir
          4th June 2004 16:08 UTC
          System::Call 'kernel32.dll::WinExec(t "net use...", i 0) i.r0'
          
          http://forums.winamp.com/showthread....hreadid=182096
         
        
        
          almoes
          4th June 2004 16:17 UTC
          Voilá!