Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need assistance converting a batch file into VBS

Status
Not open for further replies.

Teknoratti

Technical User
Aug 11, 2005
183
US
Greetings,

I'm looking for assistance in converting some of the language of a batch file into a vbs script.

I have a batch script that first looks for the existence of two particular files, "file1" or "file2"
If "file1" is present it jumps down to a section of the script stated by the GOTO command
If "file2" is present it jumps down to a different section of the script stated by the GOTO command.

ex: If Exist C:\<folder name>\file1.txt GOTO Script1:
If Exist C:\<folder name>\file2.txt GOTO Script2:

My question is, from my reading of Microsoft's VB Script step by step, it seems that I'll have to use the If..Then statement. Am I on the right track?

Please explain the logic as well, so that I can understand. Thanks in advance.

Here's the batch script which I'll need to convert to vbs language
==========================================================
If Exist C:\<folder name>\file1.txt GOTO Script1:
If Exist C:\<folder name>\file2.txt GOTO Script2:

GOTO Script1

:Script1

net use E: \\<server>\<folder>\%USERNAME% /PERSISTENT:NO
net use F: \\<server>\<folder> /PERSISTENT:NO
net use G: \\<server>\<folder> /PERSISTENT:NO
net use H: \\<server>\<folder> /PERSISTENT:NO
net use I: \\<server>\<folder> /PERSISTENT:NO
net use lpt1: \\<server>\HPLJ /PERSISTENT:NO
net use lpt2: \\<server>\HPLJ /PERSISTENT:NO

GOTO DONE

:Script2

net use E: \\<server>\<folder>\%USERNAME% /PERSISTENT:NO
net use F: \\<server>\<folder> /PERSISTENT:NO
net use G: \\<server>\<folder> /PERSISTENT:NO
net use H: \\<server>\<folder> /PERSISTENT:NO
net use I: \\<server>\<folder> /PERSISTENT:NO
net use lpt1: \\<server>\HPLJ /PERSISTENT:NO
net use lpt2: \\<server>\HPLJ /PERSISTENT:NO

GOTO DONE


:DONE
==================================================
 
You need to load both the File System Object and the Network object so you can use its methods to access the file system and map a drive, respectively. The logic is quite simple and converting it to vbs will be a snap. if File A exists, execute command set A and end. Else, if File B exists, execute command set B.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objNetwork = CreateObject("WScript.Network")

if (objFSO.FileExists("C:\fileA.txt")) then
   objNetwork.MapNetworkDrive "E:", "\\serverA\folderA"
   ...
elseif (objFSO.FileExists("C:\fileB.txt")) then
   objNetwork.MapNetworkDrive "E:", "\\serverB\folderB"
   ...
end if

-Geates


 
Anyway, why converting a working batch file to VBS ???
 
@PHV
We are converting some XP stations to Windows 7 and pushing the logout scripts from W2K3 Server. My understanding is that the old batch scripts won't work with Windows 7 and that's why I need to convert them to vbs.

Your thoughts?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top