Help in WHSCRIPT

Hello can someone help me with this script where I need to extend the path after the shared folder to direct to the subfolder one level down?

if InGroup ("TimeT") or InGroup ("TimeW") then
      mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$")
end if

This is snippet of the script. this works but if I want to go one folder deeper meaning "SharedApps$ -> TimeFolder" thats when I get stuck short on sharing the TimeFolder out directly which if I can avoid I would like too. Any help would be appreciated.
OZSGAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
oBdAConnect With a Mentor Commented:
Adding the subfolder(s) to the share name should work just fine:
mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$\SomeFolder") 

Open in new window

0
 
David Johnson, CD, MVPOwnerCommented:
What is WHSCRIPT ?? Do you mean vbscript i.e. a .vbs file? which uses either cscript or wscript ? all you can do is connect to the proper share and then CD to the subdirectory
0
 
oBdACommented:
If you post code, then please
* put it into "Style Code" tags
* put all relevant code portions in
That said, you can of course map directly into subfolders since Windows 2000, and that works with VBScript as well.
Set objNetwork = WScript.CreateObject("WScript.Network")
strRemoteShare = "\\SomeServer\SomeShare\SomeFolder\SomeOtherFolder" 
objNetwork.MapNetworkDrive "S:", strRemoteShare, False

Open in new window

i can't tell how that fits into your current script, because you're using a function "MapDrive" that you didn't post.
It might work if you just add the folder after what seems to be share:
mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$\SomeFolder")

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
OZSGAuthor Commented:
HI guys my apologies, I hope this is what you were looking for

Set WshNetwork = CreateObject("WScript.Network")
Set WshShell   = CreateObject( "WScript.Shell" )

vbquote = Chr(34)

'* Get user's login name, domain, Computer Name and define where the PC is located, etc
strUserID = WshNetwork.Username
strDomain = WshNetwork.UserDomain
strDomainUserID = LCase(strDomain + "\" + strUserID)
PCName = WshNetwork.ComputerName
PCLocation = ucase(left(PCName,2))
PCRoom = ucase(mid(PCName,3,3))
PCNumber = ucase(mid(PCName,6))

'* Get group memberships
strUserGroups = ""
Dim objNameSpace
Dim objUser
Const ADS_READONLY_SERVER = 4

'* Use the OpenDSObject method with the ADS_READONLY_SERVER value to grab the "closest" domain controller
Set objNameSpace = GetObject( "WinNT:" )

'* Connect to user object in the domain
Set objUser = objNameSpace.OpenDSObject("WinNT://" & strDomain & "/" & strUserID, "", "", ADS_READONLY_SERVER)

'* Process each group
For Each objGroup In objUser.Groups
      'Add group name to list
      strUserGroups = strUserGroups & objGroup.Name & ","
Next
Set objNameSpace = Nothing


if InGroup ("Thin Clients") then
'      No bgs login script processing required for auto connected thin client computers
      wscript.quit
end if


Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections


mapmydrive = ""

' mapmydrive = MapDrive ("X:", "SERVER2", "Apps")      
' mapmydrive = MapDrive ("Y:", "SERVER1", "Public")

if InGroup ("XUsers") then

      Set userhomeSystemObject = CreateObject("Scripting.FileSystemObject")
      if not(userhomeSystemObject.FolderExists("P:\")) then
            mapmydrive = MapDrive ("P:", "SERVER1", strUserID + "$")
      else
'            WScript.Echo "Home Drive already mapped"
      End If
      set userhomeSystemObject = nothing

'      Remark out any lines which you don't want XUserxx to have automatically mapped ...

'      mapmydrive = MapDrive ("X:", "SERVER2", "Apps")      
'      mapmydrive = MapDrive ("Y:", "SERVER1", "Public")
'      mapmydrive = MapDrive ("Z:", "SERVER1", "xshare")
else
      mapmydrive = MapDrive ("M:", "SERVER3", "Media")
      mapmydrive = MapDrive ("X:", "SERVER2", "Apps")

      if InGroup ("ComedClass") then
            mapmydrive = MapDrive ("Y:", "SERVER1", "ComedPublic")
      else
            mapmydrive = MapDrive ("Y:", "SERVER1", "Public")
      end if
end if


if InGroup ("Staff") or InGroup ("Domain Admins") then
      mapmydrive = MapDrive ("M:", "SERVER3", "Media")
'      mapmydrive = MapDrive ("S:", "STAFFFS", "Staff")
      mapmydrive = MapDrive ("R:", "PROBLEMSERVER", "Reports$")

      Set userhomeSystemObject = CreateObject("Scripting.FileSystemObject")
      if not(userhomeSystemObject.FolderExists("P:\")) then
            mapmydrive = MapDrive ("P:", "PROBLEMSERVER", strUserID + "$")
      else
'            WScript.Echo "Home Drive already mapped"
      End If
      set userhomeSystemObject = nothing

end if

if InGroup ("Staff") or InGroup ("Emergency Teachers") then
      mapmydrive = MapDrive ("S:", "STAFFFS", "Staff")
end if


if InGroup ("_Deltalink Users") then
'*      mapmydrive = MapDrive ("U:", "GOMEZ", "Upfront$")
end if

if InGroup ("TimeT") or InGroup ("TimeW") then
      mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$")
end if
0
 
oBdACommented:
Again:
1. please put code inside "Style Code" tags (directly above the Edit box, or use {code}{/code}, using square brackets instead of curly ones)
Try the difference for yourself:
1. attempt to fully select the code you posted above, and put it into the clipboard.
2. attempt the same with the code block I posted above (note the "Select all" link below the box).

2 put all relevant code portions in
Most of the code is not relevant. You want to us to tell you how to map a drive to a subfolder, but you left out the function you're using ("MapDrive") that does the actual mapping.

Have you tried yet if it works if you just add the subfolder like I suggested above?
0
 
OZSGAuthor Commented:
HI oBdA, again I apologize for not noting that first time I am doing this code thing, I got what you are saying so hopefully I am finally doing this right, unfortunately I have not had the opportunity to try your code suggestion out for the subfolder yet, will try this tomorrow,


Set WshNetwork = CreateObject("WScript.Network")
Set WshShell   = CreateObject( "WScript.Shell" )

vbquote = Chr(34)

'* Get user's login name, domain, Computer Name and define where the PC is located, etc
strUserID = WshNetwork.Username
strDomain = WshNetwork.UserDomain
strDomainUserID = LCase(strDomain + "\" + strUserID)
PCName = WshNetwork.ComputerName
PCLocation = ucase(left(PCName,2))
PCRoom = ucase(mid(PCName,3,3))
PCNumber = ucase(mid(PCName,6))

'* Get group memberships
strUserGroups = ""
Dim objNameSpace
Dim objUser
Const ADS_READONLY_SERVER = 4

'* Use the OpenDSObject method with the ADS_READONLY_SERVER value to grab the "closest" domain controller
Set objNameSpace = GetObject( "WinNT:" )

'* Connect to user object in the domain
Set objUser = objNameSpace.OpenDSObject("WinNT://" & strDomain & "/" & strUserID, "", "", ADS_READONLY_SERVER)

'* Process each group
For Each objGroup In objUser.Groups
	'Add group name to list
	strUserGroups = strUserGroups & objGroup.Name & ","
Next
Set objNameSpace = Nothing


if InGroup ("Thin Clients") then
'	No bgs login script processing required for auto connected thin client computers
	wscript.quit
end if


Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
==========================================================================================

Function MapDrive (strDrive, strServer, strShare)

'* Usage:	mapmydrive = MapDrive ("X:", "ServerHostingShare", "ShareName")

MapDrive = ""
Dim strPath       'Full path to share
Dim blnError      'True / False error condition
blnError = False

'*	Disconnect Drive if drive letter is already mapped.

Set oDrives = WshNetwork.EnumNetworkDrives
For i = 0 to oDrives.Count - 1 Step 2
	if oDrives.Item(i) = strDrive then
		WshNetwork.RemoveNetworkDrive strDrive, true, true
'		WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
	end if
Next

'*	Build path to share
strPath = "\\" & strServer & "\" & strShare
WshNetwork.MapNetworkDrive strDrive, strPath, False

'*	Check error condition and output appropriate user message
If Err.Number <> 0 OR blnError = True Then
	'Display message box informing user that the connection failed
	'This error message is specific for "special" machine configuration i.e. Drama PCs

	Select Case PCLocation
		Case "DR"
			strMsg = "Unable to connect to network share - " & "(" & strPath & ") share unavailable. " & vbCrLf & vbCrLf & strServer & " is not turned on or unplugged from network. " & vbCrLf & vbCrLf & "If you want to reconnect, please check " & strServer & " (either turn on or reconnect network cable), " & vbCrLf & "then logout from this PC, login again and '" & strPath & "' should reconnect. " & vbCrLf & "Otherwise ignore this message. " & vbCrLf & vbCrLf & strDrive & " not connected (mapped). "

		Case Else
			strMsg = "Unable to connect to network share. " & vbCrLf & "Please contact IT Support. " & vbCrLf & "Let them know that you are unable to connect to the " & "'" & strPath & "' share. " & vbCrLf & strDrive & " not connected (mapped). "

	End Select

'*	WshShell.Popup strMsg,2, "Drive Connection (mapping) Error !", 48
	MapDrive = ""
Else
	MapDrive = strPath
End If
End Function

Function InGroup(strGroup)
'*	Search strUserGroups for strGroup

InGroup = False
If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True
End Function

Function CheckPrn (strPrinter)
'*	oPrinters is an array - even items are local printer names, odd items are UNC network printer names
	CheckPrn=False
	For i = 0 to oPrinters.Count - 1 Step 2
		If Instr(1,LCase(strPrinter), Lcase(oPrinters.Item(i+1)), 1) then
'*			WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
			CheckPrn=True
		End If
	Next
End Function

Function CheckDrv (strDrive)
'*	oDrives is an array   - even items are local names of logical drives, odd items are associated UNC share names

End Function

sub drvprn
'         WScript.Echo "Network drive mappings:"
         For i = 0 to oDrives.Count - 1 Step 2
'            WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
         Next
'         WScript.Echo 

'         WScript.Echo "Network printer mappings:"
         For i = 0 to oPrinters.Count - 1 Step 2
'            WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
         Next
End sub

Sub Cleanup
'* Exit script
On Error Resume Next
'Set FileSys     = Nothing
Set WshNetwork  = Nothing
Set WshShell    = Nothing
Wscript.Quit()

End Sub

==========================================================================================



mapmydrive = ""

' mapmydrive = MapDrive ("X:", "SERVER2", "Apps")	
' mapmydrive = MapDrive ("Y:", "SERVER1", "Public")

if InGroup ("XUsers") then

	Set userhomeSystemObject = CreateObject("Scripting.FileSystemObject")
	if not(userhomeSystemObject.FolderExists("P:\")) then
		mapmydrive = MapDrive ("P:", "SERVER1", strUserID + "$")
	else
'		WScript.Echo "Home Drive already mapped"
	End If
	set userhomeSystemObject = nothing

'	Remark out any lines which you don't want XUserxx to have automatically mapped ...

'	mapmydrive = MapDrive ("X:", "SERVER2", "Apps")	
'	mapmydrive = MapDrive ("Y:", "SERVER1", "Public")
'	mapmydrive = MapDrive ("Z:", "SERVER1", "xshare")
else
	mapmydrive = MapDrive ("M:", "SERVER3", "Media")
	mapmydrive = MapDrive ("X:", "SERVER2", "Apps")

	if InGroup ("ComedClass") then
		mapmydrive = MapDrive ("Y:", "SERVER1", "ComedPublic")
	else
		mapmydrive = MapDrive ("Y:", "SERVER1", "Public")
	end if
end if


if InGroup ("Staff") or InGroup ("Domain Admins") then
	mapmydrive = MapDrive ("M:", "SERVER3", "Media")
'	mapmydrive = MapDrive ("S:", "STAFFFS", "Staff")
	mapmydrive = MapDrive ("R:", "PROBLEMSERVER", "Reports$")

	Set userhomeSystemObject = CreateObject("Scripting.FileSystemObject")
	if not(userhomeSystemObject.FolderExists("P:\")) then
		mapmydrive = MapDrive ("P:", "PROBLEMSERVER", strUserID + "$")
	else
'		WScript.Echo "Home Drive already mapped"
	End If
	set userhomeSystemObject = nothing

end if

if InGroup ("Staff") or InGroup ("Emergency Teachers") then
	mapmydrive = MapDrive ("S:", "STAFFFS", "Staff")
end if


if InGroup ("_Deltalink Users") then
'*	mapmydrive = MapDrive ("U:", "GOMEZ", "Upfront$")
end if

if InGroup ("TimeT") or InGroup ("TimeW") then
	mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$")
end if

Open in new window

0
 
OZSGAuthor Commented:
hi oBdA

I will try that tomorrow and let you know what we find. Thanks so much for your assistance on this.
0
 
OZSGAuthor Commented:
Hi guys it worked great. thanks for all your help oBdA!
0
 
OZSGAuthor Commented:
the solution provided by oBdA was exactly what needed to be done hence giving all points to the contributor.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.