Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripts not working. What am I missing 1

Status
Not open for further replies.

ftoddt

Technical User
Apr 26, 2003
180
US
Ok,
I am very new at this and trying to learn about this in the Windows 2000 Scripting Guide about vbScript, wsh, wmi, etc. I downloaded Windows Script 5.6 and installed it. I copied this script and changed the folder I wish to delete for practice as Scripts in the C: drive.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("SELECT * FROM Win32_Directory WHERE Name = 'c:\\Scripts'")
For Each objFolder in colFolders
errResults = objFolder.Delete
Wscript.Echo errResults
Next

or this script:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\Scripts")
pause


But all I get is nothing but an error such as this:
'objFSO.DeleteFolder' is not recognized as an i
operable program or batch file.

I feel like there is a dll or library file or program that is not installed in my win2k machine.
So what am I missing. All help is appreciated. Thanks
 
you have this info in a file???
what is the file extension???
it needs to be .vbs

also the 'pause' wont work in vbscript. which makes me think you have this code in a .bat file
 
mrmovie,
Thanks for your quick answer.
You are absolutely correct. I thought all the login type scripts were .bat All the other scripts that are already in place for user logins are .bat Can I use at .vbs in a login script???
Todd
 
yeap, you can use any extension for a logonscript, .exe , .vbs etc.
 
mrmovie,
Thanks your great. I appreciate this late night help. I had no idea that the extensions .vbs .exe etc would work as login scripts. The other logins scipts that I used were for mapping drives to certain users and looked like this as a .bat file

echo on
net time /set /yes
net use s: /home
net use /delete r:
net use /delete v:
net use r: \\wsd-fs1\reading

Are you saying that I could relable this .bat file a .vbs or am I going to have to change the language for .vbs to work..
Thanks again,
Todd
 
thanks for the star Todd
the language you have posted will only work in a batch file.
if you want to run a vbscript then you will have to put in vbscript language.
you cannot mix the two.

if you give me detailed info on what you want i will try and help you get something together. i spent 3 months writing a logonscript for my company, we 8000 seats and 65 locations. you might say i have some experience in it :)
its 12.39 in the afternoon here so youve got my attention for a few hours, ive got to take lunch though ;-)
 
You are most deserving and welcome for the star. What I am trying to accomplish is what is in the .bat file by mapping and deleting certain drives. The new part that now has me looking at .vbs (thanks to you) is to try and delete certain folders on student computers that may house msn messenger, or yahoo chat etc. Any and all help is greatly appreciated. With 8000 seats, I can certainly imagine how much you have had to do...
Thanks again,
Todd
 
Set WshShell = CreateObject("WScript.Shell")
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")

'deleting a folder
Call deleteFolder("%windir%\test")
Call deleteFolder("c:\dump")

Set WshShell = Nothing
Set FSO = Nothing
'###### sub to delete a folder
Sub deleteFolder(sFolder)

Dim sF2Delete
sF2Delete = WshShell.ExpandEnvironmentStrings(sFolder)
If FSO.FolderExists(sF2Delete) Then
FSO.DeleteFolder(sF2Delete)
End If

End Sub

'on what basis do you want to map drives?, AD group membership?? or something like that???
 
I have different scipts for different groups in our active directory. There are certain map drives that I set up for teachers, staff, and students. Some mapping is required for certain server based databases to be accessed by students but then I hide the mapped drives using group policy so they don't visually see them.
In your example above, is the folder called "dump" the one you are deleting?? Boy I can see that I have to study up a lot more which is how you learn.
Todd
 
yes thats right.
i created a sub routine whcih can be called from anywhere in the script and therefore reused.
so the 2 calls to the sub

Call deleteFolder("%windir%\test")
Call deleteFolder("c:\dump")

will try and delete

"%windir%\test
"c:\dump"

if they exist.

for the drive mappings you will first need to get the groups the user is a member of.
test this and see if it works for you


Set WshShell = CreateObject("WScript.Shell")
strUsername = WshShell.ExpandEnvironmentStrings("%UserName%")
Set dicGroupNames = Wscript.CreateObject("Scripting.Dictionary")
Set objUser = GetObject("WinNT://domainnamehere/" & strUsername)
Set Groups = objUser.Groups
For Each aGroup In Groups
If Not dicGroupNames.Exists(LCase(aGroup.Name)) Then
dicGroupNames.Add LCase(aGroup.Name), "1"
End If
Next
Set objUser = Nothing


'how to check if a user is a member?
Msgbox dicGroupNames.Exists("adgroupnamehere")

'loop through all groups???
For Each aGroup In dicGroupNames
Msgbox aGroup
Next

'you will need to change 'domainnamehere'
 
Sorry so late back to you response wise. I got off night shift and went home to sleep. It will take me a while to analyize what you have done above but I do have a question for you.
If your above script breakes down action base on what group a user belongs to, is is really necessary for me to do it that way if I have or make seperate scripts for each group. In active directory I can designate what script a user uses and can modify it by group. For example, for the group of students, I have one script, for teachers a different script, for staff another different script, etc etc.
Thanks again,
Todd
 
i would say having one script will make it easier to maintain.
the way i go about it is to have one central script and then allow each location, adgroup, or user have a .ini file (if they wish) which configures the logon for them.
these ini files contain the info for drive/printer mappings etc. that way once you have tested and released your central script you should never have to change it when you want to add/modify mappings etc
i guess it comes down to your own personal taste sometimes
 
Thanks again. I will try it both ways as I get better at this. I played around with some .vbs to delete and map some drives and it worked perfectly. I can make this work for individuals for sure and will try to make a master script as you suggest. Your help has been greatly appreciated.
Thanks
 
mrmovie
If you have the time, I have made a script that will delete a mapped drive if it is there. It looks like this:

Set objNetwork = WScript.CreateObject("Wscript.Network")
objNetwork.MapNetworkDrive "N:", "\\NWSFS01CJ\USERS\G3ODCFTT", True


Is there anything more that I can add so I don't get an error if the drive does not exist; something that first checks to see if there is one and deletes if there is or moves on if there isn't. If you have the time to write a couple of lines that would do that for me, I would appreciate it.
Thanks
Todd
 
'to loop through current drives

Set enumDrives = WshNetwork.EnumNetworkDrives
For i = 0 to enumDrives.Count -1
If enumDrives.Item(i) <> "" Then
Msgbox LCase(enumDrives.Item(i)) & "=" & LCase(enumDrives.Item(i + !)
End If

'to check if a drive already exists
If FSO.DriveExists("d:") Then
Msgbox "drive d is in use"
End If

i would say if you are trying to map an N drive to \\server1\share1 then you should do the following:

check is N drive is in use
If N drive is in use check if it is mapped to \\server1\share1
If it is then you dont need to disconnect and you dont need to reconnect, you can leave it alone
 
Ok so if I want to delete the mapped drive but I want to check and see if there is an "N" drive first, I would write something like this:

Set objNetwork = WScript.CreateObject("Wscript.Network")
If FSO.DriveExists("N:") Then
objNetwork.RemoveNetworkDrive "N:"
end if

And if I wanted to map the drive, I would do something like this:

Set objNetwork = WScript.CreateObject("Wscript.Network")
If FSO.DriveExists("N:") Then objNetwork.MapNetworkDrive "N:", "\\NWSFS01CJ\USERS\G3ODCFTT", True
end if

Does that look right
Thanks again..
 
presuming you have FSO, WshShell , WshNetwork already sorted

your deleting a drive looks cool

mapping a drive:

strDrive = "N:"
strShare = "\\NWSFS01CJ\USERS\G3ODCFTT"
If Not FSO.DriveExists(strDrive) Then
'map the drive
If FSO.FolderExists(strShare) Then
objNetwork.MapNetworkDrive strDrive, strShare, True
End If
Else
'should go off and check if the N drive is already mapped to correct place
'not connected to the right place, then
objNetwork.RemoveNetworkDrive "N:"
'map the drive
If FSO.FolderExists(strShare) Then
objNetwork.MapNetworkDrive strDrive, strShare, True
End If
End If

'there are lots of way round of doing it. depends how many pre checks you want to do.
some people dont bother checking if the share is available before trying to map it? they trap the error afterwards.
either way i would advise logging all this information. if you have a duff share mapping in your script or ini file , i.e. the server is no longer available you will want to log this somewhere so you can alter the ini file/script so that the logon times will not be affected. its takes a while for WSH to return from a FOlderExists or map drive call if the share is unavailable. say a new user has been setup but someone forgot to make them a homedir
 
Ok you lost me somewhat. What do you mean by "presuming you have FSO, WshShell , WshNetwork already sorted". I do not know if I do or not. Are these these script dlls or programs...to bind to thru vbs?? I am sorry. I am so weak at this its pathetic. Thanks for your time.
 
dont worry about ftoddt, we have to start somewhere. i didnt have a clue (and prob still dont) how to program until i found this forum. keep your chinup, read all the posts you can and pennies will start dropping :)

what i meant was i didnt put in the typical start

Option Explicit

Dim FSO, WshShell, objNetwork
Dim strDrive, strShare

Set objNetwork = WScript.CreateObject("Wscript.Network")
Set WshShell = CreateObject("WScript.Shell")
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")

strDrive = "N:"
strShare = "\\NWSFS01CJ\USERS\G3ODCFTT"

Call MapDrive(strDrive, strShare)

'sub to map drive when passes DriveLetter, ShareName
Sub MapDrive(sDrive, sShare)

If Not FSO.DriveExists(sDrive) Then
'map the drive
If FSO.FolderExists(sShare) Then
objNetwork.MapNetworkDrive sDrive, sShare, True
End If
Else
'should go off and check if the N drive is already mapped to correct place
'not connected to the right place, then
objNetwork.RemoveNetworkDrive sDrive
'map the drive
If FSO.FolderExists(sShare) Then
objNetwork.MapNetworkDrive sDrive, sShare, True
End If
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top