I need to pass a %1 variable from a batch/DOS script into my vbs
script. Here's what I tried but it doesn't work.

BATCH FILE*******************
@echo on
for /f "Tokens=1" %%i in (c:\newacct\exp.txt) do call :parse %%i
goto end
:parse
cscript /nologo pwdset.vbs
:end

VBS SCRIPT***************************************
set oUser = GetObject("LDAP://cn=%1,ou=Users,dc=domain,dc=com")
oUser.Put "pwdLastSet", CLng(-1)
oUser.Setinfo
'

******************************************************************************************
Basically I have a flat text file with 1 entry per line of the user
ID's I need to reset the pwdlastset value to a -1. So I am parsing the
entries from that file with DOS and trying to pass that value into the
VBS script.
Can I do this all in VBS? If so can someone write the script that would
use the file ref'd in my above DOS script for a VBS script?

Much thanks!!!!

RE: pass variable from DOS to VBS by ucthakur-NOSPAM

ucthakur-NOSPAM
Fri Mar 17 12:46:27 CST 2006

Pass the argument to VBS file by changing this line:
> cscript /nologo pwdset.vbs

to:

cscript /nologo pwdset.vbs %1

this will send the value of %1 as argument to VBS file. In VBS file, you
need to read the value of this argument and substitute it in your GetObject
call. your VBS willl then look like this:

set wsArgs = wscript.arguments 'Wscript Arguments collection
if wsArgs.count <> 1 then
wscript.echo "No user name specified."
wscript.quit 'end script.
end if
'wscript.echo "LDAP://cn=" & wsArgs(0) & ",ou=Users,dc=domain,dc=com"
set oUser = GetObject("LDAP://cn=" & wsArgs(0) & ",ou=Users,dc=domain,dc=com")
oUser.Put "pwdLastSet", CLng(-1)
oUser.Setinfo

2nd option - if you want it all in VBS.
-------------------------------------
dim fso
set fso = createObject("scripting.filesystemObject")
set ts = fso.openTextFile("c:\newacct\exp.txt")

while not ts.atEndOfStream
strUser = ts.readLine
strLDAP = "LDAP://cn=" & strUser & ",ou=Users,dc=domain,dc=com"
wscript.echo strLDAP 'to verify that data is read correctly from file
set oUser = GetObject(strLDAP)
oUser.Put "pwdLastSet", CLng(-1)
oUser.Setinfo
wend
ts.close


You can learn more about VBScripting at Microsoft Technet Script Center
http://www.microsoft.com/technet/scriptcenter/topics/beginner/firststeps.mspx
http://www.microsoft.com/technet/scriptcenter/resources/begin/default.mspx
http://www.microsoft.com/technet/scriptcenter/default.mspx

-----
Umesh

"Old programmers never die. They just terminate and stay resident."



"rwh@rodharrison.com" wrote:

> I need to pass a %1 variable from a batch/DOS script into my vbs
> script. Here's what I tried but it doesn't work.
>
> BATCH FILE*******************
> @echo on
> for /f "Tokens=1" %%i in (c:\newacct\exp.txt) do call :parse %%i
> goto end
> :parse
> cscript /nologo pwdset.vbs
> :end
>
> VBS SCRIPT***************************************
> set oUser = GetObject("LDAP://cn=%1,ou=Users,dc=domain,dc=com")
> oUser.Put "pwdLastSet", CLng(-1)
> oUser.Setinfo
> '
>
> ******************************************************************************************
> Basically I have a flat text file with 1 entry per line of the user
> ID's I need to reset the pwdlastset value to a -1. So I am parsing the
> entries from that file with DOS and trying to pass that value into the
> VBS script.
> Can I do this all in VBS? If so can someone write the script that would
> use the file ref'd in my above DOS script for a VBS script?
>
> Much thanks!!!!
>
>

Re: pass variable from DOS to VBS by Stuffin

Stuffin
Fri Mar 17 12:54:22 CST 2006

Try something like this:

Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
WScript.Echo objArgs(I)
Next<rwh@rodharrison.com> wrote in message
news:1142618320.963954.305930@i39g2000cwa.googlegroups.com...
>I need to pass a %1 variable from a batch/DOS script into my vbs
> script. Here's what I tried but it doesn't work.
>
> BATCH FILE*******************
> @echo on
> for /f "Tokens=1" %%i in (c:\newacct\exp.txt) do call :parse %%i
> goto end
> :parse
> cscript /nologo pwdset.vbs
> :end
>
> VBS SCRIPT***************************************
> set oUser = GetObject("LDAP://cn=%1,ou=Users,dc=domain,dc=com")
> oUser.Put "pwdLastSet", CLng(-1)
> oUser.Setinfo
> '
>
> ******************************************************************************************
> Basically I have a flat text file with 1 entry per line of the user
> ID's I need to reset the pwdlastset value to a -1. So I am parsing the
> entries from that file with DOS and trying to pass that value into the
> VBS script.
> Can I do this all in VBS? If so can someone write the script that would
> use the file ref'd in my above DOS script for a VBS script?
>
> Much thanks!!!!
>



Re: pass variable from DOS to VBS by shb*NO*SPAM*

shb*NO*SPAM*
Fri Mar 17 12:55:03 CST 2006

On 17 Mar 2006 09:58:41 -0800, rwh@rodharrison.com wrote:

>I need to pass a %1 variable from a batch/DOS script into my vbs
>script. Here's what I tried but it doesn't work.
>
>BATCH FILE*******************
>@echo on
>for /f "Tokens=1" %%i in (c:\newacct\exp.txt) do call :parse %%i
>goto end
>:parse
>cscript /nologo pwdset.vbs
>:end
>
>VBS SCRIPT***************************************
>set oUser = GetObject("LDAP://cn=%1,ou=Users,dc=domain,dc=com")
>oUser.Put "pwdLastSet", CLng(-1)
>oUser.Setinfo
>'
>
>******************************************************************************************
>Basically I have a flat text file with 1 entry per line of the user
>ID's I need to reset the pwdlastset value to a -1. So I am parsing the
>entries from that file with DOS and trying to pass that value into the
>VBS script.
>Can I do this all in VBS? If so can someone write the script that would
>use the file ref'd in my above DOS script for a VBS script?
>
>Much thanks!!!!
>

Try this kill-test.bat batch file (kills running notepad
sessions) to see if it passes info in the way you want (offset
two spaces for line wrap detection):

=======kill-test.bat======

@echo off
echo Set objArgs = WScript.Arguments >kill.vbs
echo processEXE = objArgs(0) >>kill.vbs
echo Set objWMIService = GetObject("winmgmts:" _ >>kill.vbs
echo ^& "{impersonationLevel=impersonate}!\\" _ >>kill.vbs
echo ^& "." ^& "\root\cimv2") >>kill.vbs
echo Set colProcess = objWMIService.ExecQuery _ >>kill.vbs
echo ("Select * from Win32_Process Where Name = '" ^&
processEXE ^& "'" ) >>kill.vbs
echo For Each objProcess in colProcess >>kill.vbs
echo objProcess.Terminate() >>kill.vbs
echo next >>kill.vbs
echo wscript.quit >>kill.vbs
echo In ~5 seconds I'm out of here! >out.txt
start notepad.exe out.txt
ping -n 5 127.0.0.1 >nul
start kill.vbs notepad.exe


Re: pass variable from DOS to VBS by rwh

rwh
Fri Mar 17 13:16:48 CST 2006

Thanks for your response. Do you know if there is a way to direct the
vbs script to run against a specific Domain Controller? I have 4 of
them and would like to test this against one DC so I don't have to wait
for them to all sync to see if the change takes place.


Re: pass variable from DOS to VBS by ucthakur-NOSPAM

ucthakur-NOSPAM
Fri Mar 17 13:46:37 CST 2006

I did not heard of a way to force a vbscript (with adsi code) to run against
a particular DC. however, I found that most of the time, it will execute on
DC that has authenticated your logon request.

set | find "LOGONSERVER" /i
will give you the name of DC that has authenticated your login request.

so, you can always execute your script, and check the results by connecting
to this DC from ADUC. you need not to wait for replication to take place.

--
-----
Umesh

"Old programmers never die. They just terminate and stay resident."



"rwh@rodharrison.com" wrote:

> Thanks for your response. Do you know if there is a way to direct the
> vbs script to run against a specific Domain Controller? I have 4 of
> them and would like to test this against one DC so I don't have to wait
> for them to all sync to see if the change takes place.
>
>

Re: pass variable from DOS to VBS by rwh

rwh
Fri Mar 17 15:02:53 CST 2006

Here is what I got to work, thanks to several people, including a very
intellegent guy here at work (Thanks Tom)
This is a single vbs script, no need for a batch file

****** VBS SCRIPT *******************************************
Dim objFileSystem, objInputFile
Dim strOutputFile, inputData, strData

Const OPEN_FILE_FOR_READING = 1

' generate a filename base on the script name, here readfile.in
' place path and file name of input file for your data. 1 entry per
line
strOutputFile = "c:\exp.txt"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile(strOutputFile,
OPEN_FILE_FOR_READING)

' read everything in an array
inputData = Split(objInputFile.ReadAll, vbNewline)

For each strData In inputData
' For each line in the file, do this:

strQuery = "LDAP://cn=" + strData + ",ou=test,dc=domain,dc=com"
WScript.Echo strQuery
'set oUser = GetObject("LDAP://cn=" + strData)
'WScript.Echo strData + " " + oUser.Get("lastPwdSet")

set oUser = GetObject("LDAP://cn=" + strData +
",ou=test,dc=domain,dc=com")
oUser.Put "pwdLastSet", 0
oUser.Setinfo
oUser.Put "pwdLastSet", -1
oUser.Setinfo
Next

objInputFile.Close
Set objFileSystem = Nothing

WScript.Quit(0)
*****************************************************************
Note, that I had to set the pwslastset value to 0 first then to -1
immediatly afterward. For some reason you can't just set it to -1 from
scratch. I've not been able to find any MS articles to explain why that
is.