Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Unable to make the '<>' operator work correctly

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1182
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Unable to make the '<>' operator work correctly
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Unable to make the '<>' operator work correctly - 7/26/2004 6:32:56 PM   
  Speedy

 

Posts: 8
Score: 0
Joined: 7/7/2004
From:
Status: offline
Hi, I want to run a script which can delete all but specified local user profiles on Win2K workstations.I have sent similar post before but I still can't make the script run correctly. Thanks everyone...

' VBScript source code
Set fs = CreateObject ("Scripting.FilesystemObject")
Set f = fs.GetFolder("C:\Documents and Settings")
Set subf = f.SubFolders
If lcase(z.Name) <> "administrator" or lcase(z.Name) <> "all users" or lcase(z.Name) <> "default user" Then
z.Delete True
Else
WScript.Echo "can't delete folder " & z.Name
End If
Next
Set fs = Nothing

Well this doesn't work! I think it actually does not recognize the '<>' operators because I get a message "Access denied", as it is trying to delete the active 'administrator' folder...
The original code which works fine with '=' operators is below:

' VBScript source code
Set fs = CreateObject ("Scripting.FilesystemObject")
Set f = fs.GetFolder("C:\Documents and Settings")
Set subf = f.SubFolders
dim z
For Each z in subf
If z.Name = "Administrator" or z.Name = "All Users" or z.Name = "Default User" Then
WScript.Echo "can't delete folder " & z.Name
Else
z.Delete True
End If
Next
Set fs = Nothing
 
 
Post #: 1
 
 Re: Unable to make the '<>' operator work correctly - 7/27/2004 12:10:58 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Try changing the OR's to AND's. I did this and was able to get the top script to work (only popped up a message box. Which I would recommened you do until you are sure your code is working. Don't want to accidently lose something that is needed.

(in reply to Speedy)
 
 
Post #: 2
 
 Re: Unable to make the '<>' operator work correctly - 7/27/2004 8:15:37 PM   
  Speedy

 

Posts: 8
Score: 0
Joined: 7/7/2004
From:
Status: offline
I tried changing it to AND's before, and I do have an 'echo' message instead of the
z.Delete in the top code. Either way it outputs the echo message as many times as there are folders inside the specified folder.

(in reply to Speedy)
 
 
Post #: 3
 
 Re: Unable to make the '<>' operator work correctly - 7/28/2004 7:10:40 AM   
  rhcsgcsc

 

Posts: 4
Score: 0
Joined: 7/28/2004
From:
Status: offline
I may be missing something, but in the top post, Object is never defined. It has no way to compare z.Name. Could this be the problem, because your logic looks correct.

(in reply to Speedy)
 
 
Post #: 4
 
 Re: Unable to make the '<>' operator work correctly - 7/28/2004 7:29:35 AM   
  rhcsgcsc

 

Posts: 4
Score: 0
Joined: 7/28/2004
From:
Status: offline
VBScript cannot use the <> for a not equal to operator.
This code is similar to what you posted above. Hope it helps.

'*********************************************************************
Set fs = CreateObject ("Scripting.FilesystemObject")
Set f = fs.GetFolder("C:\Documents and Settings")
Set subf = f.SubFolders
For each z in subf
If not((lcase(z.Name) = "administrator") or (lcase(z.Name) = "all users") or (lcase(z.Name) = "default user")) Then
'z.Delete True
wscript.echo "Deleting Folders: " & z.Name
Else
WScript.Echo "can't delete folder " & z.Name
End If
Next
Set fs = Nothing
'*********************************************************************

(in reply to Speedy)
 
 
Post #: 5
 
 Re: Unable to make the '<>' operator work correctly - 7/28/2004 8:27:02 PM   
  Speedy

 

Posts: 8
Score: 0
Joined: 7/7/2004
From:
Status: offline
Excellent mate, thanks very much for your help 'IF NOT' worked. :)

(in reply to Speedy)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Unable to make the '<>' operator work correctly Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts