Scripters,
I am new to the VB-scripting world!
I would like to get the following done by scripting so that I can install Flash.
The steps are:-
1. Open Internet Options.
2. Click on “Connections” tab.
3. Click on “LAN Settings” button.
4. Deselect the “Automatically Detect Settings” checkbox.
5. Check the “Use a proxy server for your LAN (These settings will not apply to dial-up or VPN connections).” checkbox.
6. Enter the address “172.16.3.150” in the “Address” text field and “80” in the “Port” text field.
7. Check the “Bypass proxy server for local addresses” check box.
8. Click “OK”, and “OK” again.
9. Open “Internet Explorer” and navigate to “http://aihdownload.adobe.com/bin/install_flashplayer11x64ax_gtbd_aih.exe”
and open the file.
So is it possible to get this all to work in a script? I would like to use this in GPO to run on all client desktops.
I appreciate any help provided! Thank you very much!
You don't need IE and its gui to make an http request behind a proxy server. You can download a file using WinHttpRequest object (with proxy information, see SetProxy).
e.g.
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim oHttp
Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
With oHttp
'Make request
.SetTimeouts 5000,5000,5000,30000
.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, "172.16.3.150:80"
.Open "GET", "http://aihdownload.adobe.com/bin/install_flashplayer11x64ax_gtbd_aih.exe", False
.Send
If oHttp.Status = 200 Then
'Save Response
With CreateObject("ADODB.Stream")
.Open
.Type = adTypeBinary
.Write oHttp.ResponseBody
.SaveToFile "C:\setup.exe", adSaveCreateOverWrite
.Close
End With
'Run Executable
CreateObject("WScript.Shell").Run "C:\setup.exe"
WScript.Echo "Completed!"
Else
WScript.Echo "Download Failed"
End If
End With
Set oHttp = Nothing
Related
Please help,
my vbscript: saveGSheet.vbs (to download sheet) works fine when manually run. I woud like to automat this, but an automatic task will NOT download the file.
How to run this in Task Scheduler? On Windows Server 2008.
Task Scheduler - settings:
Action: Run program: saveGSheet.bat with code:
c:\Windows\SysWOW64\cscript saveGSheet.vbs
Run task as LOCAL SERVICE
Run task when NOT LOGGED IN
Tried already:
Run with highest privileges does not help
creating "Desktop" folders does not help
"Log on as a batch job" does not help
Possible reasons:
Not logged in means objects doesnt work properly - possibly needs to be run in interactive mode like MS Excel? I do not understand what in my script needs to be run interactive (logged in)?
"MSXML2.XMLHTTP.3.0"
"ADODB.Stream"
Vbscript:
' Set your settings
strFileURL = "https://docs.google.com/spreadsheets/d/1B5jBWGHT1dGKCwE9KLTlFsyymNCc1s4AH1LcFQOcwqQ/export?format=xlsx"
strHDLocation = "C:\file.xlsx"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
'Response 200 is OK, now download sheet
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Note: I should not use any third party apps, so I dont use wget for example.
EDIT: Made log file as suggested, result:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\AppBackUpTools\ALM\NotifikaceVSE\SLA_Escalation\download_excel\saveGSheet.vbs(27, 3) ADODB.Stream: Write to file failed.
modify your saveGSheet.bat as below:
c:\Windows\SysWOW64\cscript saveGSheet.vbs > %temp%\saveGSheet.log 2>&1
after the task is executed, examine the content of the log file at %temp%\saveGSheet.log that should give you some clue to debug further
You have no rights to write there. Change the folder ie to the folder where you have vbscript.
I am trying to create a HTA file that, among other things, connects to a remote network drive on a Windows 7 PC. In order to do this I need a username / password. I have the following code:
Sub ConnectDrive
Set objNetwork = CreateObject("WScript.Network")
Set oShell = CreateObject("Shell.Application")
objNetwork.MapNetworkDrive "x:", "\\testsystem3\temp", False, User, Pass
If Err.Number = 0 Then
oShell.NameSpace("x:").Self.Name = "Temp on TS3"
End If
Set oShell = Nothing
Set objNetwork = Nothing
End Sub
User and Pass are the actual username and password used in order to connect.
The problem is that I get a Logon failure error message: "Logon failure: unknown user name or bad password".
I am sure that the username and password are ok since using the net use x: \\testsystem3\temp /user:User pass command connects the drive successfully.
Any suggestions how to get this to work? I could turn off password protected sharing on the Windows 7 machine but I wouldn't like that...
Thank you!
I have a Vb script which calls a bat file.the bat file contans logic to send email.i run the bat file using objShell.run.when i give an invalid email server name in the bat file.the email is not sent.But objShell.run always returns a 0.How to do exception handling in this case.please help
If you are using the objShell.run method it is running a separately process and do not care about the current process you are running. I would look at the ProcessStartInfo. I think you can redirect the input/output/error stream from the ProcessStartInfo. Here and here are some link about it
Your best bet would be to use CDO to send your email right from the VBScript. Otherwise, error handling in Batch is extremely difficult and you will have to resort to exit codes.
If you want to send without installation then try the second method. you have to initialize the objects. In that example i remove h in the link because i can't post links
CDO.MESSAGE
'Script to send an email through QTP nice one Set oMessage = CreateObject("CDO.Message")
'==This section provides the configuration information for the remote SMTP server. '==Normally you will only change the server name or IP. oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserver") =""
'Server port (typically 25) oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update oMessage.Subject = "Test Mail" oMessage.Sender = "" oMessage.To ="" 'oMessage.CC = "" 'oMessage.BCC = "" oMessage.TextBody = "Test Mail from QTP"&vbcrlf&"Regards,"&vbcrlf&"Test" oMessage.Send
Set oMessage = Nothing
I have the eventual goal of determining that a particular database on a particular server with particular credentials is running, but I would settle, at this point, for the ability to check and see if a server is actually up on the network. Does anyone have a way of doing this? I seem to be drawing a blank.
Michael
try this
Dim target
Dim result
target= "172.19.130.96"
Set shell = WScript.CreateObject("WScript.Shell")
Set shellexec = shell.Exec("ping " & target)
result = LCase(shellexec.StdOut.ReadAll)
If InStr(result , "reply from") Then
WScript.Echo "Server alive"
Else
WScript.Echo "Not Alive"
End If
There maybe better ways especialy given you end goal but this should work and at least point you in the correct direction.
Here's an alternative solution that uses the Win32_PingStatus WMI class (note: this class is only available on Windows XP and later):
strServer = "stackoverflow.com"
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strServer & "'")
If oPing.StatusCode = 0 Then
WScript.Echo "Server is available."
Else
WScript.Echo "Server is not available."
End If
More ping script samples here: Why Doesn't My Ping Script Run on Windows 2000 Computers?
If you update the ping command so it only sends one echo request the script executes faster, if you've got an unreliable network this might not be best but for local LAN it's useful.
Dim target
Dim result
target= "172.19.130.96"
Set shell = WScript.CreateObject("WScript.Shell")
Set shellexec = shell.Exec("ping -n 1 " & target)
result = LCase(shellexec.StdOut.ReadAll)
If InStr(result , "reply from") Then
WScript.Echo "Server alive"
Else
WScript.Echo "Not Alive"
End If
For checking whether your database server is up, you can use tools like nmap. Then you can call it in your vbscript using exec() as per normal.
We are working on automating the deployment of some IIS applications. I've used cscript.exe inside a windows batch file to create the web app and such. There are however a few settings currently done by hand that I need to automate. Namely, if you look at the properties of an app, under Directory Structure -> Authentication and access control -> Edit, I need to uncheck Enable anonymous access and check Integrated Windows authentication.
Is there an easy way to do this from a windows batch file?
EDIT: I should clarify this is IIS 6.0, so appcmd is not available.
hope this helpes:
http://forums.iis.net/t/1159665.aspx
I answered a very similar question a wee while back. The example uses the asdutil.vbs tool which you can call from your batch file:
Setting NTAuthenticationProviders at an Application level in IIS 6 (Stack Overflow)
Updated:
Because you've already got a CScript script to create the website, you can just set the AuthFlags in the script:
'' Some values just as an example
iisNumber = 668
ipAddress = "172.16.3.200"
hostName = "myserver.com"
wwwfolder = "c:\mysites\www"
Dim serverBindings(1)
serverBindings(0) = ipAddress & ":80:www." & hostName
serverBindings(1) = ipAddress & ":80:" & hostName
'' Create server
Set w3svc = GetObject("IIS://localhost/w3svc")
Set newWebServer = w3svc.Create("IIsWebServer", iisNumber)
newWebServer.ServerBindings = serverBindings
newWebServer.ServerComment = "Server is: " & hostName
newWebServer.SetInfo
'' Create /root app
Set rootApp = newWebServer.Create("IIsWebVirtualDir", "ROOT")
rootApp.Path = wwwFolder
rootApp.AccessRead = true
rootApp.AccessScript = true
rootApp.AppCreate(True)
rootApp.AuthFlags = 4 '' <== Set AuthFlags here
rootApp.SetInfo
See Configure Windows Authentication (IIS 7):
appcmd set config /section:windowsAuthentication /enabled:true | false
For IIS 6 probably WMI is the alternative:
Creating Sites and Virtual Directories, and Setting Properties Using WMI
IIsWebServiceSetting (WMI)
AuthFlags
Dim sSitePath = "1" 'Set the site ID here
Set oSite = GetObject("IIS://localhost/" & sSitePath & "/root")
Select Case oSite.AuthFlags
Case 1
Wscript.Echo "Anonymous"
Case 2
Wscript.Echo "Basic"
Case 4
Wscript.Echo "NTLM"
Case 6
Wscript.Echo "MD5"
Case 64
Wscript.Echo "Passport"
End Select