Solved

Help in WHSCRIPT

Posted on 2016-08-22
9
41 Views
Last Modified: 2016-08-23
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.
0
Comment
Question by:OZSG
  • 5
  • 3
9 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41766102
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
 
LVL 83

Expert Comment

by:oBdA
ID: 41766383
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
 

Author Comment

by:OZSG
ID: 41766770
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
 
LVL 83

Expert Comment

by:oBdA
ID: 41766792
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:OZSG
ID: 41766858
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
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41766872
Adding the subfolder(s) to the share name should work just fine:
mapmydrive = MapDrive ("T:", "Stafffs", "Sharedapps$\SomeFolder") 

Open in new window

0
 

Author Comment

by:OZSG
ID: 41766908
hi oBdA

I will try that tomorrow and let you know what we find. Thanks so much for your assistance on this.
0
 

Author Comment

by:OZSG
ID: 41768019
Hi guys it worked great. thanks for all your help oBdA!
0
 

Author Closing Comment

by:OZSG
ID: 41768021
the solution provided by oBdA was exactly what needed to be done hence giving all points to the contributor.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now