How do I write a batch file to run a .vbs file for each user login on a server 2003 network from a shared folder?

I have been mandated by my state deparment of information services to run a .vbs on all of my workstations in my network. I'm new to scripting and batch files. My environment is Windows 2003 server with all Windows XP workstations connected across a MAN. They tell me it will only run from a mapped network drive. The problem is that we do not have just one mapped drive common to all machines. We do have a shared netlogon folder where we keep our login scripts. It is where I keep my scripts to automatically add printers. I need suggestions on how I can run the .vbs file using a .vbs script or a .bat file.
a_fishy_fellaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
I've no doubt those will work but possibly over complicated if you know what drive letters are free in your environment then there is nothing stopping you doing just:

REM Make sure X: isn't already in use
 net use x: /delete 2>NUL
REM Map drive X: to netlogon share
 net use X: \\server\netlogon /persistent:no
REM Run VBS Script
 cscript //nologo x:\yourscript.vbs
REM Remove X: drive mapping again
net use x: /delete

It would perhaps be best to create a shared drive across all locations or perhaps if all locations have an "S:" shared drive say then just put the VBS in the same path for all of them, e.g. s:\scripts and just add

cscript //nologo s:\scripys\yourscript.vbs

to each of the login scripts the different locations run.

Steve
0
 
SteveGTRCommented:
Here's a batch file I have that will dynamically map a drive to a UNC.
@echo off 
 
setlocal
 
set unc=\\server\share\dir
 
set drive=
for /F "tokens=1,2" %%a in ('net use * "%unc%" 2^>NUL') do if "%%a"=="Drive" set drive=%%b
 
if "%drive%"=="" echo Could not map to %unc%&goto :EOF
 
REM ** Do your common processing. You could call another batch file or vbs script if you want.
REM ** This code is just for testing and can be removed
echo Drive=%drive%
pause
 
REM ** Keep this line to delete the mapped drive
net use "%drive%" /del

Open in new window

0
 
RobSampsonCommented:
Hi, I don't know if a batch file can do this, but if you run this VBS via a login script, it will look for the next available drive letter, map it to a specific shared folder, run the VBS that requires the mapped drive (hopefully not letter dependant!), and then remove the mapped drive.....

Part of it was taken from here:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0122.mspx

'===============
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")

strShareToMap = "\\Server\Share\"
strVBSFile = "MyScript.vbs"
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

For Each objDisk in colDisks
    objDictionary.Add objDisk.DeviceID, objDisk.DeviceID
Next

For i = 67 to 90
    strDrive = Chr(i) & ":"
    If objDictionary.Exists(strDrive) Then
    Else
        'Wscript.Echo strDrive & " is the next available drive letter."
        objNetwork.MapNetworkDrive strDrive, strShareToMap, False, False
        objShell.Run "wscript """ & strDrive & "\" & strVBSFile & """", 1, True
        objNetwork.RemoveNetworkDrive strDrive, True
        Wscript.Quit
    End If
Next
'Wscript.Echo "There are no available drive letters on this computer.
'===============

Regards,

Rob.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SteveGTRCommented:
"The problem is that we do not have just one mapped drive common to all machines."
0
 
Steve KnightIT ConsultancyCommented:
Sure I took that to mean that at siteA there is \\servera\share and siteB there is \\serverb\share just no central share that everyone maps to.  In which case a) just create one, b) use the netlogon share or c) copy it to each site and run it from there.

Anyway reading again it could be one of a number of things (as usual) so no doubt "a_fishy_fella" will come back soon!

Steve
0
 
a_fishy_fellaAuthor Commented:
Thanks for the suggestions. I will be back as soon as I get a chance to breathe.
0
 
RobSampsonCommented:
Breathing is a good thing....try to keep that up..... ;-P .... hopefully you return, not too blue-faced....
0
 
a_fishy_fellaAuthor Commented:
dragon-it: So far your solution looks elegant and useful for a simpleton like me. I'll work with it  and let you know.
0
 
Steve KnightIT ConsultancyCommented:
No problem, just ask if you need any help.

Steve
0
 
a_fishy_fellaAuthor Commented:
dragon-it,

What does the //nologo do?
0
 
a_fishy_fellaAuthor Commented:
I just added these last two lines to my existing login scripts.

net use v: \\dc1\pcaudit
v:\PCAuditor.VBS

I'll delete the mapped drive later. Steve, you get the prize. All of you presented viable solutions. However, Steve kept it simple and I was able to learn little. Thank you all for your participation.
0
 
Steve KnightIT ConsultancyCommented:
No problem, thanks.  The //nologo.  When you run a vbs file with cscript it will have some info. on the scripting engine etc. to start with.  adding the //nologo (yes two //) stops that.
0
 
Steve KnightIT ConsultancyCommented:
SteveGTR are you still listening to emails around here - someone was asking about a script you wrote and wondered what happened to you?
0
 
Steve KnightIT ConsultancyCommented:
BTW looking back don't know why I didn't just suggest doing

pushd \\server\share
cscript //nologo yourscript.vbs
popd
0
 
SteveGTRCommented:
I still read email notifications, but don't participate on EE actively anymore. Glad to see you are still at it :)
0
 
Steve KnightIT ConsultancyCommented:
You should try again, I don't know if something annoyed you here or just your situation changed but we learned so much over the years from your scripts etc.... surely you must be in need of some more decorating / gardening / kids hair cutting T-shirts by now ;-)

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_26489134.html?cid=1576

I suppose at least it suddenly became easier to get answers around here, though billprew especially flying along and nicking everything going now!

Steve
0
 
SteveGTRCommented:
You know it has been so long since I've done this I think that somebody else can surely do this. Good luck :)
0
All Courses

From novice to tech pro — start learning today.