Sign in to follow this  
Followers 0
morg

RunWait(@ComSpec

13 posts in this topic

I am trying to get SC.exe to work in autoit but I am having issues with the password in the autoit script. If I run the command in the windows command prompt it works fine but not with the autoit script. I figure I must have something incorrect in my syntax however I don't seem to be able to figure out what that is. I am wondering if there is a special character Autoit doesn't like. The sc.exe command works like this sc.exe config "Service Name" obj= "DOMAIN\User" password= "password" on windows fine so I know I have the syntax correct there. The autoit script runs but the password isn't correct because the servie won't start when I use this in autoit.

$pas = "%pass{}%$$@#("
$Use = "Domain\Username"

RunWait(@ComSpec & " /c " & " net Stop ServiceName", "", @SW_HIDE)
RunWait(@ComSpec & " /c " & " sc config ServiceName obj= " & $Use & " password= " & $pas & "", "", @SW_HIDE)
RunWait(@ComSpec & " /c " & " net start ServiceName", "", @SW_HIDE)

Share this post


Link to post
Share on other sites



Have you tried using RunAs instead?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The commandline you type in CMD, does that contain the double quotes around any of the parameter?

If so, they are missing in your runwait statements.

use /k to debug your commandline statements.

Edited by Jos
1 person likes this

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

Share this post


Link to post
Share on other sites

The commandline you type in CMD, does that contain the double quotes around any of the parameter?

If so, they are missing in your runwait statements.

use /k to debug your commandline statements.

Yes in the command line in windows I use double quotes around service, user and password. I am missing that for the serice name and I will add that in. As for /k switch how do I incorporate that into autoit to debug, I am not fimilar with that?

Share this post


Link to post
Share on other sites

Have you tried using RunAs instead?

I don't need to the runas because I am running the script with credentials that enable me to change the logon user name and password. When I tested from the command prompt I was logged in the server with rights to change the username and password on the server and it worked fine but when I tried to change it using the auotit script it didn't work. Thanks for the reply I apprciate it..:mellow:

Share this post


Link to post
Share on other sites

For debugging use this format:

RunWait(@ComSpec & ' /k net Stop "ServiceName"', "")

I tried the above to debug using the correct service name worked great! When I tried RunWait below to change the user the message I got back was successful but my script still will not put the password in correct, I am totally stumped.

$aPas = "password"
$aUse = "Domain\UserName"
RunWait(@ComSpec & ' /k sc config "ServiceName" obj= ' & $aUse & ' password= ' & $aPas & '', "", @SW_SHOW)

Share this post


Link to post
Share on other sites

You do not have double quotes around the userid and password yet. Could that be it?

Ok do you mean where I am declaring them in the variable? If so how do I add the double quotes?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

RunWait(@ComSpec & " /c " & " sc config ServiceName obj= " & $Use & " password= " & $pas & "", "", @SW_HIDE)

 

this is you anser :& @CRLF &

RunWait(@ComSpec & " /c sc config ServiceName obj= " & $Use & @CRLF & " password= " & $pas , "", @SW_HIDE)

Edited by buscador1980

Share this post


Link to post
Share on other sites

This thread is over two years old, and the OP has not been active in all that time, so I doubt your post will do much to help. Please refrain from necro-posting in old threads.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#13 ·  Posted

I disagree... Its 9 months later still and I was searching for help with @Comspec syntax..... I came across this thread and the @CRLF was exactly what I needed to fix my problem.

So even though it may not have helped the O.P. It did help me and probably countless others who stumbled here looking for answers to similar problems...

Thx for posting buscador...

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