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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If thens !!

Status
Not open for further replies.

mrnez

Technical User
Sep 11, 2002
37
GB
Hello

I have written a wsh login script but I am having difficulty with one part of it. The script firstly gets the ip address of the machine i want the script to exit if the ip address matches 4 ip addresses I specify I can't seem to get it to work. the extract of code is below.

'Declare Global Variables
Dim shell,machine_name,fso, net, User, IPConfigSet, TextStreamObject, DomainName, strFileNames, Hwnd, ip1, ip2
Dim IP_Address : IP_Address = GetIP()

'Constants
Const C_machine = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"
Const C_roam = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\"
Const C_master = "HKLM\SYSTEM\CurrentControlSet\Services\Browser\Parameters\"
Const xpver = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\"
Const C_bmp = "c:\pa.bmp"
Const C_hosts = "c:\newhost"
Const C_keyboard = "c:\copykey20052002"
Const C_netset = "c:\netset"
Const C_xpcache = "c:\winnt\xpcache.ini"
Const C_harrisini = "c:\harrisini3007"
Const C_xpver = "c:\xpverdone"
ip1 = left(ip_address,11)
ip2 = right(ip_address,7)

msgbox ip2

if not ip2 = "102.153" or ip2 = "102.140" Then

do all the scripts stuff

Else

End the script !!

It works by having jsut one ip address to check against but with more than one it doesn't work

Surely there must be a way to do this

Thanks in advance.

Richard
 
should this be

if not ip2 = "102.153" or NOT ip2 = "102.140" Then

Regards
Steve Friday
 
Hi Steve

Tried that and it still doesn't work, it only seems to work when it is checking against one thing. If I remove the second ip address it functions as expected with the second one there it ignores the if statement

Thanks

Richard
 
Ignore last comment, didn't work,

How about reversing the logic

ip2 = "102.140"
if ip2 = "102.153" or ip2 = "102.140" Then
msgbox "do nothing or end script"
Else
msgbox "perform script"
End If Regards
Steve Friday
 
Excellent that seems to do the trick, what is the command for exiting the script. Sorry for the ignorance.

Thanks

Richard
 
I found in one of my books that NOT

"Performs a logical negation on a single expression", which answers the question as to why it did not work with

IF NOT ip2 = "102.140" Or ip2 = "102.153"

Regards
Steve Friday
 
Thats excellent thanks a lot for all your help, invaluable.

Another quick question, is it possible to compile the script into and executable using visual basics compiler ????

Thanks

Richard
 
I don't know this one - - sorry, no doubt someone else out there will Regards
Steve Friday
 
I'm unaware of any "vbscript compiler."

VB6 won't do it.

In most cases a script can be easily rewritten as a VB6 program though, with fairly minor changes. Note that since your "script" is now not hosted in WSH you will not have the WScript object to play around with. You can still create a WshShell object, but there is no way to get to the WScript object. This means anything (properties, methods, etc.) you need out of WScript you'll have to make VB6 equivalents for.

Simulating WScript.Sleep( ) for example will require a call to the Win32 API's Sleep( ) function. Lots of examples of this are floating around though, just try a search on the web or on MSDN.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top