Re: Executing a batch file only if the laptop is located on a particular subnet. by Thorsten
Thorsten
Mon Nov 29 08:42:44 CST 2004
Hi Michelle,
> The script needs to run so that if any output is created, the user doesnt
> know about it.
> For example, any messages at all need to be hidden from the user.
Call your vbscript from command line to run hidden in the cscript
environment.
Inside your vbs do not use the Msgbox method. Using the Echo method
generates messages in the (hidden) command window.
> Id need to pipe all output to a log file, for myself to access, to see if
> the script was successful or not, and need to have it appended.
Ever heard about the WriteLine Method? You can generate a textfile and
append the lines of text you are writeting to this file.
If you are familiar with vbs this shouldn't be a big problem. But take care
about the size of this file! Sometimes it is better to delete this file
first before logging all events to this file - probably every login of an
user(?). I have written a WriteLog Sub some time ago. If you want it, just
write a mail (this ng is not for binaries...)
>
> Also Thorsten, in your last line:
>
>> If bolRunCopyJob = True Then {RunYourCopyJobHere}
>
> In the
>
> {RunYourCopyJobHere}
>
> Can I just put my batch file name in here?
Huh!? I meant to put your code for copying here. Are you REALLY usung a
batch (.cmd, .bat) for doing this?
Why you are not using vbs? You'll get a better error handling and much more!
Need assistance? Just write a mail...
>
> Youve been a great help - legend.
>
> Thanks again.
>
> Simon
>
>
> "Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
> news:uyiXgug1EHA.2540@TK2MSFTNGP09.phx.gbl...
>> Hi Michelle,
>>
>> Something like that?
>> First enumerating the IP addresses, comparing them with your mask, if
>> matching, check if server is reachable. If is reachable run your copy
>> job.
>>
>> bolIsRightSubnet = False
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
>> "\root\cimv2")
>> Set IPConfigSet = objWMIService.ExecQuery _
>> ("Select IPAddress from Win32_NetworkAdapterConfiguration where
>> IPEnabled=TRUE")
>>
>> For Each IPConfig in IPConfigSet
>> If Not IsNull(IPConfig.IPAddress) Then
>> For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
>> If Left(IPConfig.IPAddress(i), 9) = "10.60.10." Then
>> bolIsRightSubnet = True
>> End If
>> Next
>> End If
>> Next
>> If bolIsRightSubnet = True Then
>> strComputerToPing = "{ServerWhereToCopyTheData}"
>> bolRunCopyJob = False
>> Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
>> ExecQuery("select * from Win32_PingStatus where address = '"_
>> & strComputerToPing & "'")
>> For Each objStatus in objPing
>> If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
>> WScript.Echo("machine " & strComputerToPing & " is not
>> reachable")
>> Else
>> bolRunCopyJob = True
>> End If
>> Next
>> End If
>> If bolRunCopyJob = True Then {RunYourCopyJobHere}
>>
>>
>> hth,
>> Thorsten
>>
>>
>> "Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
>> news:NcDqd.52485$K7.42667@news-server.bigpond.net.au...
>>> Hi guys,
>>>
>>> Hope you can help.
>>>
>>> Requirement/s:
>>>
>>> - Back up a folder on a laptop daily to a network location.
>>> - Only run the backup task IF the user is located on subnet 10.60.10.x,
>>> Id like the script to be able to check for a network connection, and if
>>> none, to abort the running of the backup.
>>> - System in question is a laptop that gets a DHCP address.
>>>
>>> I can generate the backup script, but what Id like help si the
>>> following:
>>>
>>> 1. How to code the script so that it only runs IF the laptop is given a
>>> DHCP address of 10.60.10.x and not another DHCP address, meaning it is
>>> on a different subnet
>>>
>>> 2. If the user is not connected to the LAN, and the task runs, to not
>>> run the script at all. That is, Id like the script to be able to check
>>> for a network connection, and if none, to abort the running of the
>>> backup.
>>>
>>> Any help would be greatly appreciated.
>>>
>>> Thank you..
>>>
>>> Simon
>>>
>>
>>
>
>