I am new here and new to vbs any help to get this working as I see it working would be amazing. I work for a not for profit and we have thousands of PC's I have to support. Part of which is we are creating login scripts manually for each one and it is driving me insane. I found two bits of code I am trying to push together to work as one. Essentially the first section pulls the mapped drives from a remote device and the second section prints the results to a txt file. I have it working to the point where it creates the file and puts the first line in but it is showing the drive letter from the first drive and the path of the last drive then I need to know how to make it echo each mapped drive correctly.
<code>
computername = "PLTWIN02"
username = "andersj"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objreg=getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computername & "\root\default:StdRegProv")
lngRtn = objReg.EnumKey(HKEY_USERS, "", arrRegKeys) 'enumerate HKEY_USERS to get all SIDS on remote computer
For Each strKey In arrRegKeys
If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
Else
Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")
If objsid.accountname = username Then 'if the account name of the current sid we're checking matches the accountname we're looking for then do this- -
regpath2enumerate = strkey & "\Network" 'strkey is the SID
objreg.enumkey hkey_users, regpath2enumerate, arrkeynames
If Not (IsEmpty(arrkeynames)) Then
For Each subkey In arrkeynames
regpath = strkey & "\Network\" & subkey
regentry = "RemotePath"
objreg.getstringvalue hkey_users, regpath, regentry, dapath
wscript.echo subkey & ":" & vbtab & dapath
Next
Else
wscript.echo "There are no drive letters for computer " & computername
End If
End If
End If
Next
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("\\hisjordan\Shared\Mapped\" & username & ".txt", True)
path = filesys.GetAbsolutePathName("\\hisjordan\Shared\Mapped\" & username & ".txt")
getname = filesys.GetFileName(path)
For Each subkey In arrkeynames
filetxt.WriteLine("net use " & subkey & ": """ & dapath & """ /yes")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
Next
</code>
Thank you in advance for all your help
<code>
computername = "PLTWIN02"
username = "andersj"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objreg=getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computername & "\root\default:StdRegProv")
lngRtn = objReg.EnumKey(HKEY_USERS, "", arrRegKeys) 'enumerate HKEY_USERS to get all SIDS on remote computer
For Each strKey In arrRegKeys
If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
Else
Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")
If objsid.accountname = username Then 'if the account name of the current sid we're checking matches the accountname we're looking for then do this- -
regpath2enumerate = strkey & "\Network" 'strkey is the SID
objreg.enumkey hkey_users, regpath2enumerate, arrkeynames
If Not (IsEmpty(arrkeynames)) Then
For Each subkey In arrkeynames
regpath = strkey & "\Network\" & subkey
regentry = "RemotePath"
objreg.getstringvalue hkey_users, regpath, regentry, dapath
wscript.echo subkey & ":" & vbtab & dapath
Next
Else
wscript.echo "There are no drive letters for computer " & computername
End If
End If
End If
Next
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("\\hisjordan\Shared\Mapped\" & username & ".txt", True)
path = filesys.GetAbsolutePathName("\\hisjordan\Shared\Mapped\" & username & ".txt")
getname = filesys.GetFileName(path)
For Each subkey In arrkeynames
filetxt.WriteLine("net use " & subkey & ": """ & dapath & """ /yes")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
Next
</code>
Thank you in advance for all your help