(Remote) VBS/Batch Writing/Execution

My knowledge about XP is almost a long forgotten page blown away by the wind, so I don't think i'll be much help there. Vista/Win7/Win8, i'm still okay with, and even Windows 98/2000, but I don't think that would be required here lol.

I would have to see, if my test compiled program for duplicating the tokens for the Guest account would work on my PC downstairs running on XP... You'd probably see the dust shoot out the back though it's been so long since I last used it :lol:

I'm pretty sure from the Admin account, that you'd be able to copy the tokens for the user session of any other account on the network... To integrate the functionality I had with my compiled C++ test program though, into a script. I would have to do some research...
 
Roar! I even got the commandline to the same point, works in XP but returns blank in 7!

*starts building a small-thermal nuclear device*



Edit:
Yet another variation, yet another error...
Code:
strComputer = InputBox("Computer Name or IP Address: ")
GetUserInfo strComputer, domain, currentUser, sSID
WScript.Echo "Computer: " & strComputer & vbCr & "User Domain: " & domain & vbCr & "Username: " & currentUser & vbCr & "SID: " & sSID
Function GetUserInfo(strComputer, ByRef domain, ByRef currentUser, ByRef strSID)
 strUser = InputBox("Admin Username (domain\username)") ' comment this line for current user
 strPassword = InputBox("Admin Password") ' comment this line for current user
 Set objLocator = CreateObject("WbemScripting.SWbemLocator")
 Set ntaccount = objLocator.ConnectServer(strComputer, "root\cimv2:Win32_ComputerSystem.Name=", strUser, strPassword)
 ntaccount.Security_.ImpersonationLevel = 3
 ntaccount.Security_.AuthenticationLevel = 6
 strNTAccount = ntaccount.username
 sacct = Split(strNTAccount,"\")
 domain = sacct(0)
 currentUser = sacct(1)
 Set user = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Domain='" & domain & "',Name='" & currentUser & "'")
 strSID = user.SID
End Function
Basically, I decided to add in, in addition to the impersonation, defining the admin username/password rather than let it pull it (which had failed miserably). The result was:
Code:
Script: test4.3.vbs
Line:   8
Char:   2
Error:  The RPC server is unavailable.
Code    800706BA
Source: SWbemLocator
This is really starting to enfuriate me...if I could use VB.NET, I would, I already have a working program for VB.NET, but I just can't get the VBS! :'(
 
Yeah, this even makes me a bit puzzled on what you could do to resolve this now. Through a script... I'm sure it's possible, but I just don't know how that would look like.
 
If you figure it out, let me know. Otherwise, I'll post my solution/surrender.
 
VBS isn't capable of calling a Win32 API here. PowerShell, it seems is capable of doing that. I knew it could reference .NET methods, but I wasn't sure about Win32 API's. But, through P/Invoke, perhaps.

Here's a link I found: Script Demo of calling C# and Win32 API from PowerShell

lol.. You're getting more into advanced programming by doing that though anyways. I wouldn't keep any of the VBS stuff if you've considered PowerShell. Or any of the batch.
 
Alright, I'm even more ticked than I was when it wasn't working...

The original script, from before the whole attempt at impersonation, works just fine. My issue was exactly what I'm making this script to fix...a corrupt profile... I fix about a dozen of them a day, but it didn't occur to me that my own account could be corrupt and causing my trouble. I'm sticking with the story that there were no standard symptoms of profile corruption AND the code worked with same domain machines, mainly because that's all true.

Anyways, my original rework of the code is just fine...so far... Tomorrow, when I get the time at work, I'll be trying to add the rest of my script back in. I'm trying to rework it a little, use more Sub for the sections that may be repeated and improve the processing logic.
 
Alright, I'm even more ticked than I was when it wasn't working...

The original script, from before the whole attempt at impersonation, works just fine. My issue was exactly what I'm making this script to fix...a corrupt profile... I fix about a dozen of them a day, but it didn't occur to me that my own account could be corrupt and causing my trouble. I'm sticking with the story that there were no standard symptoms of profile corruption AND the code worked with same domain machines, mainly because that's all true.

Anyways, my original rework of the code is just fine...so far... Tomorrow, when I get the time at work, I'll be trying to add the rest of my script back in. I'm trying to rework it a little, use more Sub for the sections that may be repeated and improve the processing logic.

I fix about a dozen of them a day, but it didn't occur to me that my own account could be corrupt and causing my trouble

:lol: Wow!... Now that's a bugger...
 
Alright, I'm basically back to where I was before the whole remaking of the pull users information. A few pluses though, a bit cleaner with the code, the pull user information is smaller and works across domains and OS' with one set, slightly improved logic processing for the little things like order of commands, and, of course, COMMENTS!!! :D

Anyways...as I said, with that headache working now, I'm back to where I was before, execute a second remote batch.
Code:
Option Explicit
Dim strComputer, domain, currentUser, sSID, VerBig, sacct
Dim dateMonth, dateDay, dateYear, endDate
Dim ntaccount, strNTAccount
Dim objWMI, colItems, objItem, OSystem
Dim user
Dim storeToPath, batchStoreToPath, oldStoreToPath
Dim verifyUserInfo, objAccount
Dim fileSys, batchStorePath, exportBatch
Dim objWMIService, intProcessID
Dim objFSO
Dim oldStorePath, renameBatch

'*******************************************************************************
' Prompts agent for the machine name of the users computer (IP address and
'      localhost are NOT supported [yet!])
' Returns: strComputer
'*******************************************************************************
strComputer = InputBox("Computer Name or IP Address: ")

'*******************************************************************************
' Pulls the variables strComputer, domain, currentUser, sSID, and OSystem from
'      the function GetUserInfo() to use in the rest of the script
' Returns: N/A
'*******************************************************************************
GetUserInfo strComputer, domain, currentUser, sSID, OSystem

'*******************************************************************************
' Calculates the date and formats it for use in renaming the user profile
' Returns: endDate
'*******************************************************************************
If Month(Date) < 10 Then
 dateMonth = "0" & Month(Date)
Else
 dateMonth = Month(Date)
End If
If Day(Date) < 10 Then
 dateDay = "0" & Day(Date)
Else
 dateDay = Day(Date)
End If
dateYear = Right(Year(Date), 2)
endDate = dateMonth & dateDay & dateYear

'*******************************************************************************
' Verifies the users information is correct, if not, it'll prompt the agent to
'      enter the users domain and account name
' Returns: endDate
'*******************************************************************************
verifyUserInfo = Msgbox("Is the below user information correct?" & vbCr & vbCr _
 & "Computer: " & strComputer & vbCr _
 & "System OS: " & OSystem & vbCr & vbCr _
 & "Domain: " & domain & vbCr _
 & "Username: " & currentUser & vbCr _
 & "SID: " & sSID, vbYesNo)

If verifyUserInfo = vbYes Then
 Msgbox "You answered yes."
Else
 domain = InputBox("User's Domain: ")
 currentUser = InputBox("Username: ")
 Set objAccount = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Domain='" & domain & "'" & ",Name='" & currentUser & "'")
 sSID = objAccount.SID
 pullSID()
 Wscript.Echo "Version No: " & VerBig & vbCr _
  & "OS System: " & OSystem & vbCr _
  & "User: " & domain & "\" & currentUser & vbCr _
  & "SID: " & sSID
End If

setStoragePaths()

WScript.Echo "Date (MMDDRR): " & endDate & vbCr & "storeToPath: " & storeToPath & vbCr & "batchStoreToPath: " & batchStoreToPath & vbCr & "oldStoreToPath: " & oldStoreToPath

'*******************************************************************************
' Creates, runs, and removes the remote batch to back-up the Network Drivers,
'      Printers, and PST mappings for the current user
' Returns: endDate
'*******************************************************************************
Set fileSys = CreateObject("Scripting.fileSystemObject")
Set batchStorePath = fileSys.GetFolder(batchStoreToPath)
Set exportBatch = batchStorePath.CreateTextFile("export.bat", True)
exportBatch.WriteLine("@ECHO OFF && SETLOCAL EnableDelayedExpansion")
exportBatch.WriteLine("")
exportBatch.WriteLine("ECHO Exporting data for '" & currentUser & "' with SID '" & sSID & "' to '" & storeToPath & "'...")
exportBatch.WriteLine("REG EXPORT HKU\" & sSID & "\Network " & Chr(34) & storeToPath & "\1.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT HKU\" & sSID & "\Printers " & Chr(34) & storeToPath & "\2.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\Devices" & Chr(34) & " " & Chr(34) & storeToPath & "\3.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts" & Chr(34) & " " & Chr(34) & storeToPath & "\4.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" & Chr(34) & " " & Chr(34) & storeToPath & "\5.reg" & Chr(34))
exportBatch.WriteLine("echo.>>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\1.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\2.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\3.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\4.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\5.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\1.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\2.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\3.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\4.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\5.reg" & Chr(34))
exportBatch.WriteLine("")
exportBatch.WriteLine("PAUSE && GOTO :EOF")
exportBatch.Close

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create batchStoreToPath & "\export.bat", Null, Null, intProcessID

Wscript.Echo "Instruct the customer to log out of them machine." & vbCr & vbCr _
& "Click 'OK' to rename the profile, and if Win7 to remove the SID from the registry and reboot."

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder batchStoreToPath, oldStoreToPath

Select Case VerBig
 Case "6.1"
  Set oldStorePath = fileSys.GetFolder(oldStoreToPath)
  Set renameBatch = oldStorePath.CreateTextFile("rename.bat", True)
  renameBatch.WriteLine("reg delete " & Chr(34) & "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & sSID & Chr(34) & " /f")
  renameBatch.WriteLine("shutdown -f -r -t 00")
  renameBatch.Close

  objWMIService.Create oldStorePath & "\rename.bat", Null, Null, intProcessID
End Select

'*******************************************************************************
' Function: GetUserInfo()
' Pulls the information for the current user of the defined machine either from
'      the remote machine or the domain, and uses the version indicator to
'      define if the OS and WinXP or Win7
' Returns: domain, currentUser, OSystem
'*******************************************************************************
Function GetUserInfo(strComputer, ByRef domain, ByRef currentUser, ByRef sSID, ByRef OSystem)
 On Error Resume Next
 '*******************************************************************************
 ' We're pulling the username of the current user from the defined machine and
 '      splitting it at the "\" to produce the domain name and the user name,
 '      then we call the pullSID() sub for the SID
 ' Returns: domain, currentUser
 '*******************************************************************************
 Set ntaccount = GetObject("winmgmts://" & strComputer & "/root/cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
 strNTAccount = ntaccount.username
 sacct = Split(strNTAccount,"\")
 domain = sacct(0)
 currentUser = sacct(1)
 pullSID()

 '*******************************************************************************
 ' We're pulling the operating system version from the defined machine
 ' Returns: OSystem
 '*******************************************************************************
 Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
 For Each objItem in colItems
  VerBig = Left(objItem.Version,3)
 Next
 Select Case VerBig
  Case "6.1"
   OSystem = "7"
  Case "5.1"
   OSystem = "XP"
  Case Else OSystem = "Invalid OS"
 End Select
End Function

'*******************************************************************************
' Sub: pullSID()
' Prompts the domain for the users SID
' Returns: sSID
'*******************************************************************************
Sub pullSID
 Set user = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Domain='" & domain & "',Name='" & currentUser & "'")
 sSID = user.SID
End Sub

'*******************************************************************************
' Sub: setStoragePaths()
' Uses the OSystem to define the paths used for writing in, saving to, running
'      from, and finally removing  the remote batches.  This sub also uses the
'      strComputer name to create a variation, as needed, for 
' Returns: storeToPath, batchStoreToPath, oldStoreToPath
'*******************************************************************************
Sub setStoragePaths
 ' Spot VerBig variable in previous section
 ' Note the output variable is called storeToPath
 Select Case VerBig
  Case "6.1"
   storeToPath = "C:\Users\" & currentUser
   Select Case strComputer
    Case ".", "localhost", "127.0.0.1"
     batchStoreToPath = storeToPath
     oldStoreToPath = "C:\Users\old." & currentUser & "." & endDate
    Case Else
     batchStoreToPath = "\\" & strComputer & "\c$\Users\" & currentUser
     oldStoreToPath = "\\" & strComputer & "\c$\Users\old." & currentUser & "." & endDate
   End Select
  Case "5.1"
   storeToPath = "D:\Documents and Settings\" & currentUser
   Select Case strComputer
    Case ".", "localhost", "127.0.0.1"
     batchStoreToPath = storeToPath
     oldStoreToPath = "D:\Documents and Settings\old." & currentUser & "." & endDate
    Case Else
     batchStoreToPath = "\\" & strComputer & "\d$\Documents and Settings\" & currentUser
     oldStoreToPath = "\\" & strComputer & "\d$\Documents and Settings\old." & currentUser & "." & endDate
   End Select
 End Select
End Sub
I've verified all the locations, step-by-step in the code as well as in a logic diagram, and I can't find a problem with it. I even took a machine without any user logged in, specified an account on it to use, and it created and ran the first batch but it wouldn't run the second. So, my problem isn't a matter of the user being logged off at the time, I just don't know what else it could be after the step-by-step. :S
 
Code:
Option Explicit
'On Error Resume Next
Dim strComputer, domain, currentUser, sSID, VerBig, sacct
Dim dateMonth, dateDay, dateYear, endDate
Dim ntaccount, strNTAccount
Dim objWMI, colItems, objItem, OSystem
Dim user
Dim storeToPath, batchStoreToPath, oldStoreToPath
Dim verifyUserInfo, objAccount
Dim fileSys, batchStorePath, exportBatch
Dim objWMIService, intProcessID
Dim objFSO
Dim objReg, strKeyPath, regedit, colOperatingSystems, objOperatingSystem
const HKEY_LOCAL_MACHINE = &H80000002
Dim restore

'*******************************************************************************
' Prompts agent for the machine name of the users computer (IP address and
'      localhost are NOT supported [yet!])
' Returns: strComputer
'*******************************************************************************
strComputer = InputBox("Computer Name or IP Address: ")

'*******************************************************************************
' Pulls the variables strComputer, domain, currentUser, sSID, and OSystem from
'      the function GetUserInfo() to use in the rest of the script
' Returns: N/A
'*******************************************************************************
GetUserInfo strComputer, domain, currentUser, sSID, OSystem

'*******************************************************************************
' Calculates the date and formats it for use in renaming the user profile
' Returns: endDate
'*******************************************************************************
If Month(Date) < 10 Then
 dateMonth = "0" & Month(Date)
Else
 dateMonth = Month(Date)
End If
If Day(Date) < 10 Then
 dateDay = "0" & Day(Date)
Else
 dateDay = Day(Date)
End If
dateYear = Right(Year(Date), 2)
endDate = dateMonth & dateDay & dateYear

'*******************************************************************************
' Verifies the users information is correct, if not, it'll prompt the agent to
'      enter the users domain and account name
' Returns: endDate
'*******************************************************************************
verifyUserInfo = Msgbox("Is the below user information correct?" & vbCr & vbCr _
 & "Computer: " & strComputer & vbCr _
 & "System OS: " & OSystem & vbCr & vbCr _
 & "Domain: " & domain & vbCr _
 & "Username: " & currentUser & vbCr _
 & "SID: " & sSID, vbYesNo)

If verifyUserInfo = vbYes Then
 Msgbox "You answered yes."
Else
 domain = InputBox("User's Domain: ")
 currentUser = InputBox("Username: ")
 Set objAccount = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Domain='" & domain & "'" & ",Name='" & currentUser & "'")
 sSID = objAccount.SID
 pullSID()
 Wscript.Echo "Version No: " & VerBig & vbCr _
  & "OS System: " & OSystem & vbCr _
  & "User: " & domain & "\" & currentUser & vbCr _
  & "SID: " & sSID
End If

setStoragePaths()

WScript.Echo "Date (MMDDRR): " & endDate & vbCr & "storeToPath: " & storeToPath & vbCr & "batchStoreToPath: " & batchStoreToPath & vbCr & "oldStoreToPath: " & oldStoreToPath

'*******************************************************************************
' Creates, runs, and removes the remote batch to back-up the Network Drivers,
'      Printers, and PST mappings for the current user
' Returns: N/A
'*******************************************************************************
Set fileSys = CreateObject("Scripting.fileSystemObject")
Set batchStorePath = fileSys.GetFolder(batchStoreToPath)
Set exportBatch = batchStorePath.CreateTextFile("export.bat", True)
exportBatch.WriteLine("@ECHO OFF && SETLOCAL EnableDelayedExpansion")
exportBatch.WriteLine("")
exportBatch.WriteLine("ECHO Exporting data for '" & currentUser & "' with SID '" & sSID & "' to '" & storeToPath & "'...")
exportBatch.WriteLine("REG EXPORT HKU\" & sSID & "\Network " & Chr(34) & storeToPath & "\1.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT HKU\" & sSID & "\Printers " & Chr(34) & storeToPath & "\2.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\Devices" & Chr(34) & " " & Chr(34) & storeToPath & "\3.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts" & Chr(34) & " " & Chr(34) & storeToPath & "\4.reg" & Chr(34))
exportBatch.WriteLine("REG EXPORT " & Chr(34) & "HKU\" & sSID & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" & Chr(34) & " " & Chr(34) & storeToPath & "\5.reg" & Chr(34))
exportBatch.WriteLine("type NUL >>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\1.reg" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\2.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\3.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\4.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("type " & Chr(34) & storeToPath & "\5.reg" & Chr(34) & " | find /v " & Chr(34) & "Windows Registry Editor Version 5.00" & Chr(34) & ">>" & Chr(34) & storeToPath & "\Network Mappings.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\1.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\2.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\3.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\4.reg" & Chr(34))
exportBatch.WriteLine("del " & Chr(34) & storeToPath & "\5.reg" & Chr(34))
exportBatch.WriteLine("")
exportBatch.WriteLine("PAUSE && GOTO :EOF")
exportBatch.Close

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create batchStoreToPath & "\export.bat", Null, Null, intProcessID
WScript.Sleep 1500

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(batchStoreToPath & "\export.bat")

Wscript.Echo "Instruct the customer to log out of them machine." & vbCr & vbCr _
& "Click 'OK' to rename the profile, and if Win7 to remove the SID from the registry and reboot."

objFSO.MoveFolder batchStoreToPath, oldStoreToPath

'*******************************************************************************
' Removes the SID registry entry and restarts the machine if it is running Win7
' Returns: N/A
'*******************************************************************************
Select Case VerBig
 Case "6.1"
  Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
  strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & sSID
  regedit = objReg.DeleteKey(HKEY_LOCAL_MACHINE, strKeyPath)

  Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colOperatingSystems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")

  For Each objOperatingSystem in colOperatingSystems
'   objOperatingSystem.Reboot()
  Next
End Select

Wscript.Echo "Instruct the customer to log in and wait for them to acknowledge that the Desktop has finished loading." & vbCr & vbCr _
& "Click 'OK' to copy the files from the old to new profile, restore the network drives, network printers, and Microsoft Outlook PSTs."


Select Case VerBig
 Case "6.1"
  objFSO.CopyFolder oldStoreToPath & "\Contacts", batchStoreToPath & "\Contacts"
  objFSO.CopyFolder oldStoreToPath & "\Desktop", batchStoreToPath & "\Desktop"
  objFSO.CopyFolder oldStoreToPath & "\Downloads", batchStoreToPath & "\Downloads"
  objFSO.CopyFolder oldStoreToPath & "\Favorites", batchStoreToPath & "\Favorites"
  objFSO.CopyFolder oldStoreToPath & "\Links", batchStoreToPath & "\Links"
  objFSO.CopyFolder oldStoreToPath & "\Documents", batchStoreToPath & "\Documents"
  objFSO.CopyFolder oldStoreToPath & "\Music", batchStoreToPath & "\Music"
  objFSO.CopyFolder oldStoreToPath & "\Pictures", batchStoreToPath & "\Pictures"
  objFSO.CopyFolder oldStoreToPath & "\Videos", batchStoreToPath & "\Videos"
 Case "5.1"1
  objFSO.CopyFolder oldStoreToPath & "\Desktop", batchStoreToPath & "\Desktop"
  objFSO.CopyFolder oldStoreToPath & "\Favorites", batchStoreToPath & "\Favorites"
  objFSO.CopyFolder oldStoreToPath & "\My Documents", batchStoreToPath & "\My Documents"
End Select
objWMIService.Create "regedit /s " & Chr(34) & oldStoreToPath & "\Network Mappings.reg" & Chr(34), Null, Null, intProcessID
'objFSO.DeleteFile(oldStoreToPath & "\Network Mappings.reg")

'*******************************************************************************
' Function: GetUserInfo()
' Pulls the information for the current user of the defined machine either from
'      the remote machine or the domain, and uses the version indicator to
'      define if the OS and WinXP or Win7
' Returns: domain, currentUser, OSystem
'*******************************************************************************
Function GetUserInfo(strComputer, ByRef domain, ByRef currentUser, ByRef sSID, ByRef OSystem)
 On Error Resume Next
 '*******************************************************************************
 ' We're pulling the username of the current user from the defined machine and
 '      splitting it at the "\" to produce the domain name and the user name,
 '      then we call the pullSID() sub for the SID
 ' Returns: domain, currentUser
 '*******************************************************************************
 Set ntaccount = GetObject("winmgmts://" & strComputer & "/root/cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
 strNTAccount = ntaccount.username
 sacct = Split(strNTAccount,"\")
 domain = sacct(0)
 currentUser = sacct(1)
 pullSID()

 '*******************************************************************************
 ' We're pulling the operating system version from the defined machine
 ' Returns: OSystem
 '*******************************************************************************
 Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
 For Each objItem in colItems
  VerBig = Left(objItem.Version,3)
 Next
 Select Case VerBig
  Case "6.1"
   OSystem = "7"
  Case "5.1"
   OSystem = "XP"
  Case Else OSystem = "Invalid OS"
 End Select
End Function

'*******************************************************************************
' Sub: pullSID()
' Prompts the domain for the users SID
' Returns: sSID
'*******************************************************************************
Sub pullSID
 Set user = GetObject("winmgmts:root/cimv2:Win32_UserAccount.Domain='" & domain & "',Name='" & currentUser & "'")
 sSID = user.SID
End Sub

'*******************************************************************************
' Sub: setStoragePaths()
' Uses the OSystem to define the paths used for writing in, saving to, running
'      from, and finally removing  the remote batches.  This sub also uses the
'      strComputer name to create a variation, as needed, for 
' Returns: storeToPath, batchStoreToPath, oldStoreToPath
'*******************************************************************************
Sub setStoragePaths
 ' Spot VerBig variable in previous section
 ' Note the output variable is called storeToPath
 Select Case VerBig
  Case "6.1"
   storeToPath = "C:\Users\" & currentUser
   Select Case strComputer
    Case ".", "localhost", "127.0.0.1"
     batchStoreToPath = storeToPath
     oldStoreToPath = "C:\Users\old." & currentUser & "." & endDate
    Case Else
     batchStoreToPath = "\\" & strComputer & "\c$\Users\" & currentUser
     oldStoreToPath = "\\" & strComputer & "\c$\Users\old." & currentUser & "." & endDate
   End Select
  Case "5.1"
   storeToPath = "D:\Documents and Settings\" & currentUser
   Select Case strComputer
    Case ".", "localhost", "127.0.0.1"
     batchStoreToPath = storeToPath
     oldStoreToPath = "D:\Documents and Settings\old." & currentUser & "." & endDate
    Case Else
     batchStoreToPath = "\\" & strComputer & "\d$\Documents and Settings\" & currentUser
     oldStoreToPath = "\\" & strComputer & "\d$\Documents and Settings\old." & currentUser & "." & endDate
   End Select
 End Select
End Sub
Got through the renaming stage and am working on restore. Everything starts out fine, but I keep getting an Access denied error when copying the Documents directory. I've verified the permissions to both locations and there should be no issues, especially since all the others work without a problem. Tried adding "\" to the end, as mentioned in several support discussions on the error I found through Google. Also tried adding a timed delay as it was a solution of another person with the same error, went all the way to 30 seconds, no change.

Also, for the whole second batch file thing, I just gave up on it and did some searching for an alternate means of running the regedit. Found it in regular VBScript and it works perfectly, so far. :D

Let me know if you have anything on this Access denied Error 800A0046 for Line 150.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top