Sign in to follow this  
Followers 0
Morteza

How to run START command with RunAs()?

16 posts in this topic

Anybody know why the following cod will not work?

$nResult = RunAsWait("username", @computername,"password",1,"start /wait /b reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r", @SystemDir, @SW_HIDE)

When I delete "Start /wait /b" all things work good, but a command prompt screen is appeared in milisec. I need to disappear this command prompt, so i must use "Start /wait /b" for running "Reg" command. When I execute

"start /wait /b reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r"

with Windows RunAs, all thing work good.

What is the problem with AutoIt RunAs()?

Best Regards

Share this post


Link to post
Share on other sites



Why are you using start in stead of @Comspec?

Because my need is hiding "REG" command prompt completely and just start can does it. CMD /c have a command prompt windows for itself and I can not hide it too. I used START and CMD in combination with each other, but START can not hide CMD command prompt window and this is just as the same as I use REG without START.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

becourse @comspec and Start isn't the same?

With start you can use:

start http://www.autoitscript.com

With @comspec you cant use that.

But, running start, with @comspec is a better idea i guess.

cmd /c "start /wait /b reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r"

edit: Fixed prob of the Bold tag

Edited by jaenster

-jaenster

Share this post


Link to post
Share on other sites

becourse @comspec and Start isn't the same?

With start you can use:

start http://www.autoitscript.com

With @comspec you cant use that.

But, running start, with @comspec is a better idea i guess.

cmd /c "start /wait /b reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r"

edit: Fixed prob of the Bold tag

I was tested your suggestion before my letter. When I use the following code:

$nResult = RunAsWait("username", @computername,"password",1,@comspec & " /c start /wait /b reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r", @SystemDir, @SW_HIDE)

Not only REG does not work, but also START is bypassed too and instead of one command prompt window, two command prompt is appeared in milisec.

When I changed the above code to the follow:

$nResult = RunAsWait("username", @computername,"password",1,"start /wait /b cmd /c reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r", @SystemDir, @SW_HIDE)

Command prompts were reduced to one again, but REG not work as previous.

Share this post


Link to post
Share on other sites

I was referring to something like:

$nResult = RunAsWait("username", @ComputerName, "password", 1, @comspec & " /c reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r", @SystemDir, @SW_HIDE)

:)


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I was referring to something like:

$nResult = RunAsWait("username", @ComputerName, "password", 1, @comspec & " /c reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /r", @SystemDir, @SW_HIDE)

:)

I can understand your scope, but I explained why CMD is not useful for me

Share this post


Link to post
Share on other sites

With @sw_hide you dont see the cmd :)


-jaenster

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

With @sw_hide you dont see the cmd :)

If you read my code, you will see this flag is used beforehand, but @SW_HIDE just can hide one window, CMD window or REG window. In anyway, one prompt will be appeared in milisec without START. Test it, you will see that :)

Edited by Morteza

Share this post


Link to post
Share on other sites

I can understand your scope, but I explained why CMD is not useful for me

I have seen you only use CMD in combination with START and I do not see you explicitely state you tried the command I provide.

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I have seen you only use CMD in combination with START and I do not see you explicitely state you tried the command I provide.

Please compile the following code in Console mode and ran the EXE file. I'm sure you will see my problem.

func _Test()
$nResult = RunAsWait("username", @ComputerName, "password", 1, @comspec & " /c reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /f", @SystemDir, @SW_HIDE)
EndFunc

For $a = 1 to 5000
    _Test()
Next
Edited by Morteza

Share this post


Link to post
Share on other sites

I ran your example script _Test() and I didn't see any window. Open task manager and I can see cmd.exe running several times, but no flashing cmd window. I tested in windows xp professional sp2. There is any reason why you cannot run it without @Comspec, tested and work fine for me.

$nResult = RunAsWait("username", @ComputerName, "password", 1, "reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /f", @SystemDir, @SW_HIDE)


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

If you read my code, you will see this flag is used beforehand, but @SW_HIDE just can hide one window, CMD window or REG window. In anyway, one prompt will be appeared in milisec without START. Test it, you will see that :)

-jaenster

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I ran your example script _Test() and I didn't see any window. Open task manager and I can see cmd.exe running several times, but no flashing cmd window. I tested in windows xp professional sp2. There is any reason why you cannot run it without @Comspec, tested and work fine for me.

$nResult = RunAsWait("username", @ComputerName, "password", 1, "reg add ""HKCU\software"" /v ""Value"" /d ""Data"" /t ""REG_SZ"" /f", @SystemDir, @SW_HIDE)
very strange :) With or Without CMD /c (@comspec & " /c") I just can see the following screen shot. Did you compiled it in Console mode?

post-41304-1228343866_thumb.gif

Edited by Morteza

Share this post


Link to post
Share on other sites

if you want to hide that? why you just dont start regedit.exe instant with that parameters and hide it :)?

Very simple, because Regedit can not work with on the fly registry key created codes; It can work just with REG files. :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

very strange :) With or Without CMD /c (@comspec & " /c") I just can see the following screen shot. Did you compiled it in Console mode?

No, I didn't. I'm using Scite as a editor and I press F7 to build the .exe file. When I press Ctrl+F7 which is compile and added the check mark to Create CUI instead of GUI EXE then I can see the same think as your screen shoot. Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0