Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - I need to Call this command in a vbscript

Reply
 
Old 08-03-2009   #1 (permalink)
Victor Asuquo


 
 

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 SpecsSystem Spec
Old 08-03-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: I need to Call this command in a vbscript


"Victor Asuquo" <abasi_obori@xxxxxx> wrote in message
news9C3602B-6001-4175-99EF-780E44F902F4@xxxxxx
Quote:

> 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
This is a VB Script newsgroup. Since RunAsSpc.exe is a batch file command,
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 SpecsSystem Spec
Old 08-03-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: I need to Call this command in a vbscript


"Victor Asuquo" <abasi_obori@xxxxxx> wrote in message
news9C3602B-6001-4175-99EF-780E44F902F4@xxxxxx
Quote:

> 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
--


My System SpecsSystem Spec
Old 08-04-2009   #4 (permalink)
Victor Asuquo


 
 

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
> news9C3602B-6001-4175-99EF-780E44F902F4@xxxxxx
Quote:

>> 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

Quote:

> --
>
>
My System SpecsSystem Spec
Old 08-04-2009   #5 (permalink)
Pegasus [MVP]


 
 

Re: I need to Call this command in a vbscript


"Victor Asuquo" <abasi_obori@xxxxxx> wrote in message
news0639572-EDDD-4D07-AF91-0A6A8675D487@xxxxxx
Quote:

> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:%23q3bS2EFKHA.3708@xxxxxx
Quote:

>>
>> "Victor Asuquo" <abasi_obori@xxxxxx> wrote in message
>> news9C3602B-6001-4175-99EF-780E44F902F4@xxxxxx
Quote:

>>> 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
>
I mentioned before that this is really a batch file issue. Wrapping it into
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
/useromain\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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46