![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | I need to Call this command in a vbscript Hi All; I am currently working on a script to rename all domain workstations and the script works quite well. There is however a little glitch as it needs admin credentials to run. As a solution to this i need to include this line in the script that supplies admin credentials but I do not know how to achieve this. These are the lines: runasspc.exe /program:"cmd.exe /K NETDOM.EXE RENAMECOMPUTER oldname /NewName:newname /UserD:domain\admin/PasswordD:******* /Force /Reboot:45" /domain:"domain" /user:"admin" /password:"********" /quiet Please all suggestions are welcome and will be accepted; Thanks in advance |
My System Specs![]() |
| | #2 (permalink) |
| | Re: I need to Call this command in a vbscript "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message news 9C3602B-6001-4175-99EF-780E44F902F4@xxxxxxQuote: > Hi All; > > I am currently working on a script to rename all domain workstations and > the script works quite well. There is however a little glitch as it needs > admin credentials to run. As a solution to this i need to include this > line in the script that supplies admin credentials but I do not know how > to achieve this. > > These are the lines: > > runasspc.exe /program:"cmd.exe /K NETDOM.EXE RENAMECOMPUTER oldname > /NewName:newname /UserD:domain\admin/PasswordD:******* /Force /Reboot:45" > /domain:"domain" /user:"admin" /password:"********" /quiet > > Please all suggestions are welcome and will be accepted; > > Thanks in advance you might be better off posting your question in a batch file newsgroup, e.g. in alt.msdos.batch.nt. The experts in that group would be able to tell you how to use runasspc.exe or perhaps suggest alternatives. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: I need to Call this command in a vbscript "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message news 9C3602B-6001-4175-99EF-780E44F902F4@xxxxxxQuote: > Hi All; > > I am currently working on a script to rename all domain workstations and > the script works quite well. There is however a little glitch as it needs > admin credentials to run. As a solution to this i need to include this > line in the script that supplies admin credentials but I do not know how > to achieve this. > > These are the lines: > > runasspc.exe /program:"cmd.exe /K NETDOM.EXE RENAMECOMPUTER oldname > /NewName:newname /UserD:domain\admin/PasswordD:******* /Force /Reboot:45" > /domain:"domain" /user:"admin" /password:"********" /quiet > > Please all suggestions are welcome and will be accepted; > > Thanks in advance of the wshShell object to run commands. You pass a string to the Run method that resolves to the command. The trick is to get the command exact, with spaces and quotes in the correct place. You generally concatenate several strings or string variables together into the final string passed to the Run method. Remember that all quotes embedded in a string must be doubled. For example, the command: cmd.exe /k dir "c:\Program Files\My Folder" would require the string: strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" The best way to troubleshoot is to echo the string, in this case the value of the variable strCmd, to the command prompt. If you echo the value of strCmd above, you get the command suggested. To run this command from a VBScript program you could code: ========= Set objShell = CreateObject("Wscript.Shell") strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" Wscript.Echo strCmd intReturn = objShell.Run(strCmd, 2, True) If (intReturn <> 0) Then Wscript.Echo "Return code: " & CStr(intReturn) End If ========== I'm not sure I understand the command line you specified. I cannot tell which values are hardcoded in the command, and which are variables. A guess follows. For clarity, I use line continuation characters to break up the line. Also, you may need to specify the full path to runasspc.exe: strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ & "RENAMECOMPUTER oldname /NewName:newname " _ & "/UserD:domain\admin/PasswordD:******* " _ & "/Force /Reboot:45"" " _ & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" However, I am assuming that strings like "oldname", "newname", "domain", etc., are hard coded values. If not, and they are variables with the correct values, then you must concatenate the variables into the string. For example,. if oldname and newname are variables, the command would be: strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ & "RENAMECOMPUTER " & oldname & " /NewName:" & newname & " " _ & "/UserD:domain\admin/PasswordD:******* " _ & "/Force /Reboot:45"" " _ & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" I also find it strange that there is no space after "domain\admin" and "/PasswordD". In any case, when you echo the value of strCmd to the command line, it should look exactly like the command you want to be run. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: I need to Call this command in a vbscript "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:%23q3bS2EFKHA.3708@xxxxxx Quote: > > "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message > news 9C3602B-6001-4175-99EF-780E44F902F4@xxxxxxQuote: >> Hi All; >> >> I am currently working on a script to rename all domain workstations and >> the script works quite well. There is however a little glitch as it needs >> admin credentials to run. As a solution to this i need to include this >> line in the script that supplies admin credentials but I do not know how >> to achieve this. >> >> These are the lines: >> >> runasspc.exe /program:"cmd.exe /K NETDOM.EXE RENAMECOMPUTER oldname >> /NewName:newname /UserD:domain\admin/PasswordD:******* /Force /Reboot:45" >> /domain:"domain" /user:"admin" /password:"********" /quiet >> >> Please all suggestions are welcome and will be accepted; >> >> Thanks in advance > I know nothing of the runasspc.exe utility, but you can use the Run method > of the wshShell object to run commands. You pass a string to the Run > method that resolves to the command. The trick is to get the command > exact, with spaces and quotes in the correct place. You generally > concatenate several strings or string variables together into the final > string passed to the Run method. Remember that all quotes embedded in a > string must be doubled. For example, the command: > > cmd.exe /k dir "c:\Program Files\My Folder" > > would require the string: > > strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" > > The best way to troubleshoot is to echo the string, in this case the value > of the variable strCmd, to the command prompt. If you echo the value of > strCmd above, you get the command suggested. > > To run this command from a VBScript program you could code: > ========= > Set objShell = CreateObject("Wscript.Shell") > strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" > Wscript.Echo strCmd > > intReturn = objShell.Run(strCmd, 2, True) > If (intReturn <> 0) Then > Wscript.Echo "Return code: " & CStr(intReturn) > End If > ========== > I'm not sure I understand the command line you specified. I cannot tell > which values are hardcoded in the command, and which are variables. A > guess follows. For clarity, I use line continuation characters to break up > the line. Also, you may need to specify the full path to runasspc.exe: > > strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ > & "RENAMECOMPUTER oldname /NewName:newname " _ > & "/UserD:domain\admin/PasswordD:******* " _ > & "/Force /Reboot:45"" " _ > & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" > > However, I am assuming that strings like "oldname", "newname", "domain", > etc., are hard coded values. If not, and they are variables with the > correct values, then you must concatenate the variables into the string. > For example,. if oldname and newname are variables, the command would be: > > strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ > & "RENAMECOMPUTER " & oldname & " /NewName:" & newname & " " _ > & "/UserD:domain\admin/PasswordD:******* " _ > & "/Force /Reboot:45"" " _ > & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" > > I also find it strange that there is no space after "domain\admin" and > "/PasswordD". In any case, when you echo the value of strCmd to the > command line, it should look exactly like the command you want to be run. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net and will get back to you on the details and success rate. Thanks Again Quote: > -- > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: I need to Call this command in a vbscript "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message news 0639572-EDDD-4D07-AF91-0A6A8675D487@xxxxxxQuote: > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:%23q3bS2EFKHA.3708@xxxxxx Quote: >> >> "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message >> news 9C3602B-6001-4175-99EF-780E44F902F4@xxxxxxQuote: >>> Hi All; >>> >>> I am currently working on a script to rename all domain workstations and >>> the script works quite well. There is however a little glitch as it >>> needs admin credentials to run. As a solution to this i need to include >>> this line in the script that supplies admin credentials but I do not >>> know how to achieve this. >>> >>> These are the lines: >>> >>> runasspc.exe /program:"cmd.exe /K NETDOM.EXE RENAMECOMPUTER oldname >>> /NewName:newname /UserD:domain\admin/PasswordD:******* /Force >>> /Reboot:45" /domain:"domain" /user:"admin" /password:"********" /quiet >>> >>> Please all suggestions are welcome and will be accepted; >>> >>> Thanks in advance >> I know nothing of the runasspc.exe utility, but you can use the Run >> method of the wshShell object to run commands. You pass a string to the >> Run method that resolves to the command. The trick is to get the command >> exact, with spaces and quotes in the correct place. You generally >> concatenate several strings or string variables together into the final >> string passed to the Run method. Remember that all quotes embedded in a >> string must be doubled. For example, the command: >> >> cmd.exe /k dir "c:\Program Files\My Folder" >> >> would require the string: >> >> strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" >> >> The best way to troubleshoot is to echo the string, in this case the >> value of the variable strCmd, to the command prompt. If you echo the >> value of strCmd above, you get the command suggested. >> >> To run this command from a VBScript program you could code: >> ========= >> Set objShell = CreateObject("Wscript.Shell") >> strCmd = "cmd.exe /k dir ""c:\Program Files\My Folder""" >> Wscript.Echo strCmd >> >> intReturn = objShell.Run(strCmd, 2, True) >> If (intReturn <> 0) Then >> Wscript.Echo "Return code: " & CStr(intReturn) >> End If >> ========== >> I'm not sure I understand the command line you specified. I cannot tell >> which values are hardcoded in the command, and which are variables. A >> guess follows. For clarity, I use line continuation characters to break >> up the line. Also, you may need to specify the full path to runasspc.exe: >> >> strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ >> & "RENAMECOMPUTER oldname /NewName:newname " _ >> & "/UserD:domain\admin/PasswordD:******* " _ >> & "/Force /Reboot:45"" " _ >> & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" >> >> However, I am assuming that strings like "oldname", "newname", "domain", >> etc., are hard coded values. If not, and they are variables with the >> correct values, then you must concatenate the variables into the string. >> For example,. if oldname and newname are variables, the command would be: >> >> strCmd = "runasspc.exe /program:""cmd.exe /K NETDOM.EXE " _ >> & "RENAMECOMPUTER " & oldname & " /NewName:" & newname & " " _ >> & "/UserD:domain\admin/PasswordD:******* " _ >> & "/Force /Reboot:45"" " _ >> & "domain:""domain"" /user:""admin"" /password:"*******" /quiet" >> >> I also find it strange that there is no space after "domain\admin" and >> "/PasswordD". In any case, when you echo the value of strCmd to the >> command line, it should look exactly like the command you want to be run. >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net > Thanks Richard for your most useful post. I have set to work again on this > and will get back to you on the details and success rate. Thanks Again > a VB Script file is, of course, possible but this adds another level of complexity that makes the task a lot harder to solve. If you want to keep things simple then you could do this: 1. Create a batch file "c:\Tools\RenamePC.bat" with the following two lines: @echo off NETDOM.EXE RENAMECOMPUTER oldname /NewName:newname /UserD:domain\admin/ passwordD:******* /Force /Reboot:45" /domain:"domain" /user:"admin" /password:"********" /quiet 2. Create a second batch file "c:\Tools\Invoke.bat" with the following two lines: @echo off c:\runasspc\runasspc.exe /program:c:\Tools\RenamePC.bat /user omain\Victor /password:***This approach requires exactly two lines of code: - One line for netdom.exe - One line for runasspc.exe (I'm not counting "@echo off" as a line of code . . .) It also preserves the basic structure of your idea: - Have one set of credentials for the netdom command. - Have another set of credentials that let you invoke netdom. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Synchronous call of exe with command line parameteres | PowerShell | |||
| run 2 dos commands using vbScript as a single command | VB Script | |||
| Powershell Wrapper Script Problems - Trying to Call PowershellExchange 2007 Commands from Secondary Language (Like VBScript) | PowerShell | |||
| Equivalent of powershell to vbscript command | PowerShell | |||
| How to call queued component from VBScript? | VB Script | |||