I have been writing some batch files to some specific job in my role as Desktop Support.
I have been scripting a Profile Backup script for a couple of months now, changing as the role requires and as new issues crop up.
I am trying to run the following VBS script from inside my batch file and point its output to another folder.
Set oNet= WScript.CreateObject("WScript.Network")
Set oDrives = oNet.EnumNetworkDrives
oUser = oNet.UserName
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFiletxt = oFilesys.CreateTextFile("Mapped_Network_Drives_"&oUser&".cmd", True)
For i = 0 to oDrives.Count - 1
oFiletxt.WriteLine "Net Use " & oDrives.Item(i) & " " & chr(34)& oDrives.Item(i+1) & chr(34) & " /persistent:yes"
Next
oFiletxt.Close
This VBS script was made (not by me) to export a user Mapped Network Drives to a CMD file that uses the netuse command to remap them.
If the VBS script is run itself outside of the batch file then its works fine, but when it is run inside the batch using cscript, etc, then it creates the output file Mapped_Network_Drives_%username%.cmd, but it is empty.
REM pushes script to use batch file Drive Letter as working directory
setlocal & pushd %~d0
ECHO =============================
ECHO Creating Backup Folder
ECHO =============================
MD "%UserName%_Backup"
ECHO =============================
ECHO Backing Up Mapped Network Drives
ECHO =============================
REM pushes script to use Backup Folder as working directory
pushd "%~d0%UserName%_Backup"
REM Runs VB script to backup Mapped Network Drives
cscript //nologo "%~dp0Mapped_Network_Drives.vbs"
pause
Above is a snipped of the code i have been working with.