igor7

Forum Replies Created

Viewing 30 posts - 1 through 30 (of 66 total)
  • Author
    Posts
  • Avatar
    igor7
    Member

    I’ve figured out what was wrong with issue #2, – I’ve using same variable $User in first portion of script and in second… so second $User variable override already existing, first one. That’s why file wasn’t attached to email. I’ve changed $User variable to $Username in firs portion of the script and now all good:

    [B]$Username = Read-Host -Prompt ‘Please Input Desired User Name’….
    $zipFile = “W:ADMINISTRATION$UserName.zip”…
    $filenameAndPath = “W:ADMINISTRATION$UserName.csv”[/B][/CODE]

    Issue #1: It looks like 7zip not supporting Windows-specific encrypted password, so I need convert it back to plain text before using it. I’ve found how to do it in those sites:[URL=”https://blogs.msdn.microsoft.com/timid/2009/09/10/powershell-one-liner-decrypt-securestring/#comment-6495″]https://blogs.msdn.microsoft.com/tim…/#comment-6495[/URL] and [URL=”http://www.travisgan.com/2015/06/powershell-password-encryption.html”]http://www.travisgan.com/2015/06/pow…ncryption.html[/URL]

    So, this peace of code helped me out fixing encrypted password issue:

    [CODE]$Password = Get-Content ‘W:AdministrationZipPassword.txt’| ConvertTo-SecureString
    $Marshal = [System.Runtime.InteropServices.Marshal]
    $Bstr = $Marshal::SecureStringToBSTR($Password)
    $ZipPassword = $Marshal::PtrToStringAuto($Bstr)
    $Marshal::ZeroFreeBSTR($Bstr)[/CODE]

    Issue #3: I’ve accomplished this goal using separate PowerShell script:

    [CODE]# Removing *.csv file after sending it by email

    Get-ChildItem W:Administration*.csv | Where { ! $_.PSIsContainer } | remove-item

    write-host ” ———————————————- ” -foregroundcolor DarkCyan
    write-host “”
    write-host ” All Operations Completed Successfully!!” -foregroundcolor Green
    write-host “”
    write-host ” ———————————————- ” -foregroundcolor DarkCyan[/CODE]

    Hope, my experience will be useful for somebody else…[CODE]$Username = Read-Host -Prompt ‘Please Input Desired User Name’….
    $zipFile = “W:ADMINISTRATION$UserName.zip”…
    $filenameAndPath = “W:ADMINISTRATION$UserName.csv”
    [/CODE]

    Issue #1: It looks like 7zip not supporting Windows-specific encrypted password, so I need convert it back to plain text before using it. I’ve found how to do it in those sites:https://blogs.msdn.microsoft.com/tim…/#comment-6495 and http://www.travisgan.com/2015/06/pow…ncryption.html

    So, this peace of code helped me out fixing encrypted password issue:

    $Password = Get-Content ‘W:AdministrationZipPassword.txt’| ConvertTo-SecureString
    $Marshal = [System.Runtime.InteropServices.Marshal]
    $Bstr = $Marshal::SecureStringToBSTR($Password)
    $ZipPassword = $Marshal::PtrToStringAuto($Bstr)
    $Marshal::ZeroFreeBSTR($Bstr)[/CODE]

    Issue #3: I’ve accomplished this goal using separate PowerShell script:

    [CODE]# Removing *.csv file after sending it by email

    Get-ChildItem W:Administration*.csv | Where { ! $_.PSIsContainer } | remove-item

    write-host ” ———————————————- ” -foregroundcolor DarkCyan
    write-host “”
    write-host ” All Operations Completed Successfully!!” -foregroundcolor Green
    write-host “”
    write-host ” ———————————————- ” -foregroundcolor DarkCyan[/CODE]

    Hope, my experience will be useful for somebody else…[CODE]$Password = Get-Content ‘W:AdministrationZipPassword.txt’| ConvertTo-SecureString
    $Marshal = [System.Runtime.InteropServices.Marshal]
    $Bstr = $Marshal::SecureStringToBSTR($Password)
    $ZipPassword = $Marshal::PtrToStringAuto($Bstr)
    $Marshal::ZeroFreeBSTR($Bstr)[/CODE]

    Issue #3: I’ve accomplished this goal using separate PowerShell script:

    # Removing *.csv file after sending it by email

    Get-ChildItem W:Administration*.csv | Where { ! $_.PSIsContainer } | remove-item

    write-host ” ———————————————- ” -foregroundcolor DarkCyan
    write-host “”
    write-host ” All Operations Completed Successfully!!” -foregroundcolor Green
    write-host “”
    write-host ” ———————————————- ” -foregroundcolor DarkCyan[/CODE]

    Hope, my experience will be useful for somebody else…[CODE]# Removing *.csv file after sending it by email

    Get-ChildItem W:Administration*.csv | Where { ! $_.PSIsContainer } | remove-item

    write-host ”


    ” -foregroundcolor DarkCyan
    write-host “”
    write-host ” All Operations Completed Successfully!!” -foregroundcolor Green
    write-host “”
    write-host ”


    ” -foregroundcolor DarkCyan[/CODE]

    Hope, my experience will be useful for somebody else…

    Avatar
    igor7
    Member
    in reply to: Reg Add command issue in the batch script #295083

    Yes, this is it “%%” took effect!! Thanks both of you guys for useful advice’s!!

    Avatar
    igor7
    Member
    in reply to: "If not" statement in bath script issue #295082

    Thanks for your help! After correction is working as expected!!

    Avatar
    igor7
    Member

    Re: The trust relationship between this workstation and the primary domain failed

    Ossian;284914 wrote:
    To save installing the RSAT tools, you can extract netdom.exe from one machine and copy it to others.

    Here it is:
    2) logon onto affected machine as local admin. Download and unpack following archive:https://mega.co.nz/#!Jp01zSqJ!xpXY0o…rHVdSbYI_Oxlso, run NetDom.Install.cmd with elevated privileges (working on both 32 and 64 bit OS).
    Reset machine account password by running following command from elevated cmd session:

    netdom.exe resetpwd /server: /userD: /passwordD *
    [/CODE]
    You’ll be asked for user password, reboot machine and logon as usual.
    Enjoy![CODE]
    netdom.exe resetpwd /server: /userD: /passwordD *
    [/CODE]
    You’ll be asked for user password, reboot machine and logon as usual.
    Enjoy!

    Avatar
    igor7
    Member
    in reply to: logoff user & go to sleep #295080

    Re: logoff user & go to sleep

    Quote:
    You still have to test it if it works well in all circumstances

    Thanks, Rems!!
    This solution working perfectly on Windows 7 Ent/Pro. I’m also searched for something similar…
    Just one remark… If in the system power plan enabled hibernation, the command SetSuspendState 0,1,0
    will cause computer hibernate instead of sleep. In order to force it sleep after log off, hibernation should be turned off. Reference:
    http://msdn.microsoft.com/en-us/library/aa373201.aspx
    Alternatively it is possible to use NirCmd.exe tool for forcing computer to go into standby mode even when hibernation is enabled:
    http://www.nirsoft.net/utils/nircmd.html

    Avatar
    igor7
    Member
    in reply to: Deleting files and folders older than 12 months #295079

    Re: Deleting files and folders older than 12 months

    Quote:
    I also need either the .bat file or the vb script to delete any folders older than 12 months

    May be something like this will suits your needs:

    Quote:
    Dim i, fso, f, f1, sf, BasePath, CalcResult, fNameArray()
    BasePath = “Your path here”
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set f = fso.GetFolder(BasePath)
    Set sf = f.SubFolders
    For Each f1 in sf
    CalcResult = DateDiff(“d”,f1.DateCreated,Now)
    if CalcResult > 365 then ‘desired number of days (365 = 1 year)
    ReDim preserve fNameArray(i)
    fNameArray(i) = f1.Name
    i = i + 1
    end if
    Next

    For Each fName in fNameArray
    FSO.DeleteFolder(BasePath & “” & fName)
    Next

    Save it as “DelFolder.vbs” and try…

    Avatar
    igor7
    Member
    in reply to: Redirect script output to log file #295078

    Re: Redirect script output to log file

    Rems,
    Thank you for excellent explanation!! Now it work perfect!!

    Avatar
    igor7
    Member
    in reply to: Using batch script to writedelete symbols into a text file #295077

    Re: Using batch script to writedelete symbols into a text file

    Meanwhile I’ve found some solution… and I’m trying to improve it. On scripting guys blog I’ve found explanation how can I use a script to open a file and replace text:

    Const ForReading = 1
    Const ForWriting = 2
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile(“[URL=”file://server/share/Text.txt”]\servershareText.txt[/URL]”, ForReading)
    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, “Igor “, “#Igor “)
    Set objFile = objFSO.OpenTextFile(“[URL=”file://server/share/Text.txt”]\servershareText.txt[/URL]”, ForWriting)
    objFile.WriteLine strNewText
    objFile.Close

    WScript.Echo “Done for: Igor”
    [/CODE]

    The first thing I’m searching for, how I can integrate into this script option [URL=”http://blogs.technet.com/b/heyscriptingguy/archive/2004/08/31/how-can-i-prompt-a-user-for-input.aspx”]to prompt users to enter some information[/URL] instead of ask each user to edit script to change the text string, need to be changed, manually?
    And second, how I can make script possible to check whenever in beginning of the line which contain desired text string we have # sign, remove it and whenever the line not contain this sign, insert it?
    Also I’ve found another [URL=”http://blogs.technet.com/b/heyscriptingguy/archive/2004/11/30/can-i-edit-ini-files-using-a-script.aspx”]useful article[/URL] which can help on scripting guys blog:

    [CODE]
    intLineFinder = InStr(strNextLine, “Igor”)
    [/CODE]

    This code uses the InStr method to see if the string “Igor” can be found anywhere within the variable strNextLine. But still, how I can tell to script to put or remove # sign in the beginning of the line, which contain desired string?[CODE]
    Const ForReading = 1
    Const ForWriting = 2
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.OpenTextFile(“[URL=”file://server/share/Text.txt”]\servershareText.txt[/URL]”, ForReading)
    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, “Igor “, “#Igor “)
    Set objFile = objFSO.OpenTextFile(“[URL=”file://server/share/Text.txt”]\servershareText.txt[/URL]”, ForWriting)
    objFile.WriteLine strNewText
    objFile.Close

    WScript.Echo “Done for: Igor”
    [/CODE]

    The first thing I’m searching for, how I can integrate into this script option to prompt users to enter some information instead of ask each user to edit script to change the text string, need to be changed, manually?
    And second, how I can make script possible to check whenever in beginning of the line which contain desired text string we have # sign, remove it and whenever the line not contain this sign, insert it?
    Also I’ve found another useful article which can help on scripting guys blog:

    intLineFinder = InStr(strNextLine, “Igor”)
    [/CODE]

    This code uses the InStr method to see if the string “Igor” can be found anywhere within the variable strNextLine. But still, how I can tell to script to put or remove # sign in the beginning of the line, which contain desired string?[CODE]
    intLineFinder = InStr(strNextLine, “Igor”)
    [/CODE]

    This code uses the InStr method to see if the string “Igor” can be found anywhere within the variable strNextLine. But still, how I can tell to script to put or remove # sign in the beginning of the line, which contain desired string?

    Avatar
    igor7
    Member
    in reply to: Deleting files older than 6 hours #295076

    Re: Deleting files older than 6 hours

    krokkie,
    you can try “Forfiles.exe” in a batch.

    http://forums.petri.com/showpost.php?p=94690&postcount=2

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295075

    Re: Mapping network drive for limited time

    Rems, many thanks!!
    Script working perfectly now!

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295074

    Re: Mapping network drive for limited time

    One more question…
    To make McAfee scanning script more flexible, I’m trying to replace

    [COLOR=#555a5f][FONT=Verdana]Wscript.Sleep 28800000[/FONT][/COLOR]
    [/CODE]
    [COLOR=#555a5f][FONT=Verdana]Code with process monitoring code which should check if scan32.exe is still running or not. The monitoring code currently using in my script depends on sleep option and if data on network share will grow, the scanning time will also grow, so I’ll need to measure scanning time accordingly, again and again… and this is not so suitable… Here is some application monitoring code which I’m trying to adapt for my needs:[/FONT][/COLOR]

    [CODE]
    [COLOR=#555a5f][FONT=Verdana]option explicit[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]DIM strProcess, strComputer[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]strComputer = “.” [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]strProcess = “scan32.exe”[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]’ Check if Application is running [/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]if isProcessRunning(strComputer,strProcess) then[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]wscript.echo strProcess & ” is running” [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]else[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]wscript.echo strProcess & ” is NOT running”[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]end if[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]’ Function to check if a process is running[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]function isProcessRunning(byval strComputer,byval strProcessName)[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]Dim objWMIService, strWMIQuery[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]strWMIQuery = “Select * from Win32_Process where name like ‘” & strProcessName & “‘”[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]Set objWMIService = GetObject(“winmgmts:” _[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]& “{impersonationLevel=impersonate}!\” _ [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]& strComputer & “rootcimv2”)[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]if objWMIService.ExecQuery(strWMIQuery).Count > 0 then[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]isProcessRunning = true[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]else[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]isProcessRunning = false[/COLOR][/FONT]

    [FONT=Verdana][COLOR=#555a5f]end if[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]end function[/COLOR][/FONT]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]My question is how to make this code running with “Loop” option or Loop with condition based on “isProcessRunning = false” option? If this condition is true, for example, the script will go to the next line and disconnect mapped network drive.[/FONT][/COLOR][CODE]
    Wscript.Sleep 28800000
    [/CODE]
    Code with process monitoring code which should check if scan32.exe is still running or not. The monitoring code currently using in my script depends on sleep option and if data on network share will grow, the scanning time will also grow, so I’ll need to measure scanning time accordingly, again and again… and this is not so suitable… Here is some application monitoring code which I’m trying to adapt for my needs:

    [COLOR=#555a5f][FONT=Verdana]option explicit[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]DIM strProcess, strComputer[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]strComputer = “.” [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]strProcess = “scan32.exe”[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]’ Check if Application is running [/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]if isProcessRunning(strComputer,strProcess) then[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]wscript.echo strProcess & ” is running” [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]else[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]wscript.echo strProcess & ” is NOT running”[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]end if[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]’ Function to check if a process is running[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]function isProcessRunning(byval strComputer,byval strProcessName)[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]Dim objWMIService, strWMIQuery[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]strWMIQuery = “Select * from Win32_Process where name like ‘” & strProcessName & “‘”[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]Set objWMIService = GetObject(“winmgmts:” _[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]& “{impersonationLevel=impersonate}!\” _ [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]& strComputer & “rootcimv2”)[/COLOR][/FONT]

    [COLOR=#555a5f][FONT=Verdana]if objWMIService.ExecQuery(strWMIQuery).Count > 0 then[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]isProcessRunning = true[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]else[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]isProcessRunning = false[/COLOR][/FONT]

    [FONT=Verdana][COLOR=#555a5f]end if[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]end function[/COLOR][/FONT]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]My question is how to make this code running with “Loop” option or Loop with condition based on “isProcessRunning = false” option? If this condition is true, for example, the script will go to the next line and disconnect mapped network drive.[/FONT][/COLOR][CODE]
    option explicit
    DIM strProcess, strComputer
    strComputer = “.”
    strProcess = “scan32.exe”

    ‘ Check if Application is running
    if isProcessRunning(strComputer,strProcess) then
    wscript.echo strProcess & ” is running”
    else
    wscript.echo strProcess & ” is NOT running”
    end if

    ‘ Function to check if a process is running
    function isProcessRunning(byval strComputer,byval strProcessName)
    Dim objWMIService, strWMIQuery
    strWMIQuery = “Select * from Win32_Process where name like ‘” & strProcessName & “‘”
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” _
    & strComputer & “rootcimv2”)

    if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
    isProcessRunning = true
    else
    isProcessRunning = false

    end if
    end function
    [/CODE]

    My question is how to make this code running with “Loop” option or Loop with condition based on “isProcessRunning = false” option? If this condition is true, for example, the script will go to the next line and disconnect mapped network drive.

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295073

    Re: Mapping network drive for limited time

    Quote:
    …Note.. -UINONE makes it run HIDDEN.

    Rems,
    Many thanks, now it work as expected!

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295072

    Re: Mapping network drive for limited time

    I played around with main idea to run McAfee scan using scheduled vbs rather than McAfee schedule task and discover some inconvenience… Actually if I running scan32.exe from the script with visible window:

    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath, 1, True[/CODE]

    [COLOR=#555a5f][FONT=Verdana]The scanning process ends, but scan32.exe window remain opened and as result, scan32.exe process still exist between running processes…[/FONT][/COLOR]

    [IMG]http://img37.picoodle.com/i578/igor7/9_6af_ucfvo.jpg[/IMG]

    [COLOR=#555a5f][FONT=Verdana]So, this window remains opened as well as scan32.exe exists between running processes, until I click on “Close” button. This is not so good… because I need to schedule this task to run each 24 hours and if I’ll forget to close On-Demand scan window next schedule task will not start because previous still opened…[/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana]I tried to find workaround for this issue by monitoring running scan32.exe process and after desired scanning time (I measured it previously) close On-Demand scan window using “Send Keys” option. Here is my code:[/FONT][/COLOR]

    [CODE]
    ‘Map Desired Network Drive
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    Dim strComputer, strProcess, wbemLocator, wbemServices, wbemObjectSet, wbemObject
    strDriveLetter = “Z:”
    strRemotePath = [URL=”file://\servershare”]\servershare[/URL]
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF
    ‘ Execute McAfee On-Demand Scan
    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    Const iNormalFocus = 1
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath
    objShell.Run strProgramPath, iNormalFocus
    ‘ Force script sleeping during scan time
    Wscript.Sleep 28800000
    ‘ Monitoring McAfee running process
    strComputer = “.”
    strProcess = “scan32.exe”
    Set wbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set wbemServices = wbemLocator.ConnectServer(strComputer)
    Set wbemObjectSet = wbemServices.InstancesOf(“Win32_Process”)
    For Each wbemObject In wbemObjectSet
    If LCase(wbemObject.Name) = strProcess Then
    ‘ Focus on On-Demand Scan window
    Set objShell = WScript.CreateObject(“WScript.Shell”)
    ‘ Bring the Scan window to the foreground
    objShell.AppActivate “On-Demand Scan Progress – Mapped Network Drive Scan”
    WScript.Sleep 200
    ‘ Close On-Demand Scan window
    objShell.SendKeys “%{F4}”, True
    End if
    Next
    ‘ Disconnect Network Drive
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    ‘ Send User notification
    WScript.Echo “Network drive scan has been DONE!” & _
    ” Check On-Demand log file for details”
    wscript.quit
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]I’ve ran this script few times for scan some network shares which are about few GB size and scanning process take not longer than ~ 1hour. Send Keys method working well together with AppActivate method, which is using to bring running application window to foreground. Here is explanation about Send Keys and AppActivate from Microsoft if somebody interesting…:[/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana][URL]http://technet.microsoft.com/en-us/library/ee156592.aspx[/URL][/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana]I have only problem with my own goal… When I running this script for scan network share which is about 1,5 TB size, scanning time take around 7-8 hours (as I said I measured time previously),- script is working perfect, but send keys and AppActivate methods are not worked,- On-Demand window remain opened after scanning was done. I have no idea why it’s working for “short time” scan and not working for “long time” scan… Any suggestions are much appreciated.[/FONT][/COLOR][CODE]strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath, 1, True[/CODE]

    The scanning process ends, but scan32.exe window remain opened and as result, scan32.exe process still exist between running processes…

    9_6af_ucfvo.jpg

    So, this window remains opened as well as scan32.exe exists between running processes, until I click on “Close” button. This is not so good… because I need to schedule this task to run each 24 hours and if I’ll forget to close On-Demand scan window next schedule task will not start because previous still opened…

    I tried to find workaround for this issue by monitoring running scan32.exe process and after desired scanning time (I measured it previously) close On-Demand scan window using “Send Keys” option. Here is my code:

    ‘Map Desired Network Drive
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    Dim strComputer, strProcess, wbemLocator, wbemServices, wbemObjectSet, wbemObject
    strDriveLetter = “Z:”
    strRemotePath = [URL=”file://\servershare”]\servershare[/URL]
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF
    ‘ Execute McAfee On-Demand Scan
    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    Const iNormalFocus = 1
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath
    objShell.Run strProgramPath, iNormalFocus
    ‘ Force script sleeping during scan time
    Wscript.Sleep 28800000
    ‘ Monitoring McAfee running process
    strComputer = “.”
    strProcess = “scan32.exe”
    Set wbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set wbemServices = wbemLocator.ConnectServer(strComputer)
    Set wbemObjectSet = wbemServices.InstancesOf(“Win32_Process”)
    For Each wbemObject In wbemObjectSet
    If LCase(wbemObject.Name) = strProcess Then
    ‘ Focus on On-Demand Scan window
    Set objShell = WScript.CreateObject(“WScript.Shell”)
    ‘ Bring the Scan window to the foreground
    objShell.AppActivate “On-Demand Scan Progress – Mapped Network Drive Scan”
    WScript.Sleep 200
    ‘ Close On-Demand Scan window
    objShell.SendKeys “%{F4}”, True
    End if
    Next
    ‘ Disconnect Network Drive
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    ‘ Send User notification
    WScript.Echo “Network drive scan has been DONE!” & _
    ” Check On-Demand log file for details”
    wscript.quit
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]I’ve ran this script few times for scan some network shares which are about few GB size and scanning process take not longer than ~ 1hour. Send Keys method working well together with AppActivate method, which is using to bring running application window to foreground. Here is explanation about Send Keys and AppActivate from Microsoft if somebody interesting…:[/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana][URL]http://technet.microsoft.com/en-us/library/ee156592.aspx[/URL][/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana]I have only problem with my own goal… When I running this script for scan network share which is about 1,5 TB size, scanning time take around 7-8 hours (as I said I measured time previously),- script is working perfect, but send keys and AppActivate methods are not worked,- On-Demand window remain opened after scanning was done. I have no idea why it’s working for “short time” scan and not working for “long time” scan… Any suggestions are much appreciated.[/FONT][/COLOR][CODE]
    ‘Map Desired Network Drive
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    Dim strComputer, strProcess, wbemLocator, wbemServices, wbemObjectSet, wbemObject
    strDriveLetter = “Z:”
    strRemotePath = [URL=”file://\servershare”]\servershare[/URL]
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF
    ‘ Execute McAfee On-Demand Scan
    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    Const iNormalFocus = 1
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath
    objShell.Run strProgramPath, iNormalFocus
    ‘ Force script sleeping during scan time
    Wscript.Sleep 28800000
    ‘ Monitoring McAfee running process
    strComputer = “.”
    strProcess = “scan32.exe”
    Set wbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set wbemServices = wbemLocator.ConnectServer(strComputer)
    Set wbemObjectSet = wbemServices.InstancesOf(“Win32_Process”)
    For Each wbemObject In wbemObjectSet
    If LCase(wbemObject.Name) = strProcess Then
    ‘ Focus on On-Demand Scan window
    Set objShell = WScript.CreateObject(“WScript.Shell”)
    ‘ Bring the Scan window to the foreground
    objShell.AppActivate “On-Demand Scan Progress – Mapped Network Drive Scan”
    WScript.Sleep 200
    ‘ Close On-Demand Scan window
    objShell.SendKeys “%{F4}”, True
    End if
    Next
    ‘ Disconnect Network Drive
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    ‘ Send User notification
    WScript.Echo “Network drive scan has been DONE!” & _
    ” Check On-Demand log file for details”
    wscript.quit
    [/CODE]

    I’ve ran this script few times for scan some network shares which are about few GB size and scanning process take not longer than ~ 1hour. Send Keys method working well together with AppActivate method, which is using to bring running application window to foreground. Here is explanation about Send Keys and AppActivate from Microsoft if somebody interesting…:

    http://technet.microsoft.com/en-us/library/ee156592.aspx

    I have only problem with my own goal… When I running this script for scan network share which is about 1,5 TB size, scanning time take around 7-8 hours (as I said I measured time previously),- script is working perfect, but send keys and AppActivate methods are not worked,- On-Demand window remain opened after scanning was done. I have no idea why it’s working for “short time” scan and not working for “long time” scan… Any suggestions are much appreciated.

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295071

    Re: Mapping network drive for limited time

    Quote:
    A string should be wrapped in quotes in the script, and if the string itself then double each quote that is within this string.

    Thats it!! Now it working! Here is the working code:

    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    strDriveLetter = “Z:”
    strRemotePath = “[URL=”file://server/Share”]\ServerShare[/URL]”
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF

    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath, 0, True

    Wscript.Sleep 28800000

    Set objNetwork = CreateObject(“WScript.Network”)
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    [/CODE]

    I tried to get work process monitoring code, but no success… If you’ll have time, please take a look on it..[CODE]
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    strDriveLetter = “Z:”
    strRemotePath = “[URL=”file://server/Share”]\ServerShare[/URL]”
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF

    strProgramPath = “””C:Program FilesMcAfeeVirusScan Enterprisescan32.exe”” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath, 0, True

    Wscript.Sleep 28800000

    Set objNetwork = CreateObject(“WScript.Network”)
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    [/CODE]

    I tried to get work process monitoring code, but no success… If you’ll have time, please take a look on it..

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295070

    Re: Mapping network drive for limited time

    OK, I played around and here is what I have so far:

    [COLOR=#555a5f][FONT=Verdana]Option Explicit[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]Dim objNetwork [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]strDriveLetter = “Z:” [/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]strRemotePath = “[URL=”file://server/Share”][COLOR=#0000ff]\ServerShare[/COLOR][/URL]”[/COLOR][/FONT][COLOR=#555a5f]
    [FONT=Verdana]strDriveAlias = “My Share” [/FONT]
    [FONT=Verdana]Set objNetwork = CreateObject(“WScript.Network”)[/FONT]
    [FONT=Verdana]Set oShell = CreateObject(“Shell.Application”) [/FONT]
    [FONT=Verdana]objNetwork.MapNetworkDrive strDriveLetter, strRemotePath[/FONT]
    [FONT=Verdana]If Err.Number = 0 Then[/FONT]
    [FONT=Verdana]oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias[/FONT]
    [FONT=Verdana]End IF[/FONT][/COLOR]

    [FONT=Verdana][COLOR=#555a5f]strProgramPath = “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]set objShell = createobject(“Wscript.Shell”)[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]objShell.Run strProgramPath [/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]Wscript.Sleep 60000[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]Set objNetwork = CreateObject(“WScript.Network”)[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]objNetwork.RemoveNetworkDrive “Z:”, True, True[/COLOR][/FONT]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]This script should connect network dive, execute McAfee On-Demand scan, wait for 1 minute and disconnect network drive.[/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana]For some reason command:[/FONT][/COLOR]

    [CODE]
    [COLOR=#555a5f][FONT=Verdana]strProgramPath = “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”[/FONT][/COLOR]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]not executed… I believe it vbs syntactic error. I can successfully execute the same command from the Windows “Run” menu, or if I change the command in script like:[/FONT][/COLOR]

    [CODE]
    [COLOR=#555a5f][FONT=Verdana]strProgramPath = “C:windowssystem32calc.exe”[/FONT][/COLOR]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]It working perfectly. I didn’t have match experience with script languages, so I need help with McAfee command executing and if it possible how script can monitor scan32.exe process? When it finish just delete network drive. This is will be great instead of using Wscript.Sleep command…[/FONT][/COLOR][CODE]
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell, objShell, strProgramPath
    strDriveLetter = “Z:”
    strRemotePath = “[URL=”file://server/Share”]\ServerShare[/URL]”
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF

    strProgramPath = “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    set objShell = createobject(“Wscript.Shell”)
    objShell.Run strProgramPath
    Wscript.Sleep 60000
    Set objNetwork = CreateObject(“WScript.Network”)
    objNetwork.RemoveNetworkDrive “Z:”, True, True
    [/CODE]

    This script should connect network dive, execute McAfee On-Demand scan, wait for 1 minute and disconnect network drive.

    For some reason command:

    [COLOR=#555a5f][FONT=Verdana]strProgramPath = “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”[/FONT][/COLOR]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]not executed… I believe it vbs syntactic error. I can successfully execute the same command from the Windows “Run” menu, or if I change the command in script like:[/FONT][/COLOR]

    [CODE]
    [COLOR=#555a5f][FONT=Verdana]strProgramPath = “C:windowssystem32calc.exe”[/FONT][/COLOR]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]It working perfectly. I didn’t have match experience with script languages, so I need help with McAfee command executing and if it possible how script can monitor scan32.exe process? When it finish just delete network drive. This is will be great instead of using Wscript.Sleep command…[/FONT][/COLOR][CODE]
    strProgramPath = “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}”
    [/CODE]

    not executed… I believe it vbs syntactic error. I can successfully execute the same command from the Windows “Run” menu, or if I change the command in script like:

    [COLOR=#555a5f][FONT=Verdana]strProgramPath = “C:windowssystem32calc.exe”[/FONT][/COLOR]
    [/CODE]

    [COLOR=#555a5f][FONT=Verdana]It working perfectly. I didn’t have match experience with script languages, so I need help with McAfee command executing and if it possible how script can monitor scan32.exe process? When it finish just delete network drive. This is will be great instead of using Wscript.Sleep command…[/FONT][/COLOR][CODE]
    strProgramPath = “C:windowssystem32calc.exe”
    [/CODE]

    It working perfectly. I didn’t have match experience with script languages, so I need help with McAfee command executing and if it possible how script can monitor scan32.exe process? When it finish just delete network drive. This is will be great instead of using Wscript.Sleep command…

    Avatar
    igor7
    Member
    in reply to: Mapping network drive for limited time #295069

    Re: Mapping network drive for limited time

    Quote:
    Yes it can be done with one script, simply by making it Sleep for 8 hours.
    Quote:
    The script could also monitor the process, if the process ends the scrip continue and disconnect the drive. Try to find out what process is running during the scan.

    btw do you have to use a mapped drive for the scanner? The McAfee AV product I know does support network paths, we use VSE.

    Rems,
    Thank you for respond!
    Yes, I know that McAfee support network patches, but still I prefer to map shared folder and create On-Demand scan task. In this way with McAfee GUI I have more flexibility – I can choose what to scan and what to exclude, can schedule it etc…
    You gave me a great idea – not schedule On-Demand scan and use the command which run On-Demand task within a script. Actually it sounds very good for me if it possible to create script which monitors the process, if the process ends the scrip continues and disconnects the drive. I followed your advice and found everything I need… I just need your help with script code…

    Quote:
    Try to find out what process is running during the scan.

    The process name is scan32.exe

    GUID of the task:

    “C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}[/CODE][/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]szTaskName: Mapped Network Drive Scan[/FONT][/COLOR]

    [COLOR=#555a5f][FONT=Verdana]So far this task need to be run only on one server so GUID could be hardcoded in the script.[/FONT][/COLOR]
    Thank you in advance,
    Igor.[CODE]”C:Program FilesMcAfeeVirusScan Enterprisescan32.exe” -task {19BAC370-F5A0-4C76-9591-A724D94F6059}[/CODE]
    szTaskName: Mapped Network Drive Scan

    So far this task need to be run only on one server so GUID could be hardcoded in the script.
    Thank you in advance,
    Igor.

    Avatar
    igor7
    Member

    Re: Need some help with batch script – redirect output into text file

    beddo;238856 wrote:
    Two possibilities. One is that it needs the full path to the program, including the file extension which we are currently missing.

    It is probably just the command that needs quoting

    FOR /f %%A IN (%inputfile%) do “%bpipath%/bpmedialist -mlist -U -m %%A” >> %outputfile%[/CODE]

    The for loop itself is fine, I tested it by changing everything after the do to “echo %%A” and it outputs te first phrase of every line of the batch file on a new line.[/QUOTE]

    I’ve found where was a problem! And you was right! The command itself just needs quoting in right place. Here is working code:

    [CODE]
    [COLOR=”Blue”]@echo off

    :: prepare date/time stamp
    for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%k-%%j-%%l
    for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i

    :: timestamp (ddmmmyyyy-hhmm)
    set tm=%tm::=-%
    set dtt=%dt%%tm%

    SET “bpipath=C:program filesveritasnetbackupbinadmincmd”
    SET “inputfile=tapes.txt”
    SET “outputfile=weekly-%dtt%.txt”

    IF NOT EXIST %inputfile% GOTO NEEDINPUT
    IF NOT EXIST %outputfile% GOTO CONTINUE
    echo %outputfile% already exists and will be appended to if you continue.
    echo Press any key to continue or ctrl+c to abort
    pause

    :CONTINUE
    FOR /f %%A IN (%inputfile%) do ( “%bpipath%bpmedialist” -mlist -U -m %%A >> %outputfile% )
    GOTO END

    :NEEDINPUT
    echo This script needs input file to continue, make sure %inputfile% exists
    pause

    :END[/COLOR][/CODE][CODE]FOR /f %%A IN (%inputfile%) do “%bpipath%/bpmedialist -mlist -U -m %%A” >> %outputfile%[/CODE]

    The for loop itself is fine, I tested it by changing everything after the do to “echo %%A” and it outputs te first phrase of every line of the batch file on a new line.

    I’ve found where was a problem! And you was right! The command itself just needs quoting in right place. Here is working code:

    [COLOR=”Blue”]@echo off

    :: prepare date/time stamp
    for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%k-%%j-%%l
    for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i

    :: timestamp (ddmmmyyyy-hhmm)
    set tm=%tm::=-%
    set dtt=%dt%%tm%

    SET “bpipath=C:program filesveritasnetbackupbinadmincmd”
    SET “inputfile=tapes.txt”
    SET “outputfile=weekly-%dtt%.txt”

    IF NOT EXIST %inputfile% GOTO NEEDINPUT
    IF NOT EXIST %outputfile% GOTO CONTINUE
    echo %outputfile% already exists and will be appended to if you continue.
    echo Press any key to continue or ctrl+c to abort
    pause

    :CONTINUE
    FOR /f %%A IN (%inputfile%) do ( “%bpipath%bpmedialist” -mlist -U -m %%A >> %outputfile% )
    GOTO END

    :NEEDINPUT
    echo This script needs input file to continue, make sure %inputfile% exists
    pause

    :END[/COLOR][/CODE][CODE]
    @echo off

    :: prepare date/time stamp
    for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%k-%%j-%%l
    for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i

    :: timestamp (ddmmmyyyy-hhmm)
    set tm=%tm::=-%
    set dtt=%dt%%tm%

    SET “bpipath=C:program filesveritasnetbackupbinadmincmd”
    SET “inputfile=tapes.txt”
    SET “outputfile=weekly-%dtt%.txt”

    IF NOT EXIST %inputfile% GOTO NEEDINPUT
    IF NOT EXIST %outputfile% GOTO CONTINUE
    echo %outputfile% already exists and will be appended to if you continue.
    echo Press any key to continue or ctrl+c to abort
    pause

    :CONTINUE
    FOR /f %%A IN (%inputfile%) do ( “%bpipath%bpmedialist” -mlist -U -m %%A >> %outputfile% )
    GOTO END

    :NEEDINPUT
    echo This script needs input file to continue, make sure %inputfile% exists
    pause

    :END[/CODE]

    Avatar
    igor7
    Member

    Re: Need some help with batch script – redirect output into text file

    beddo;238818 wrote:
    I’ve put some of the extra line breaks back in to make it more readable…

    The do command probably needs enclosing. It may even need some quotes but I can’t remember offhand so if the brackets aren’t working try this:

    Code:
    FOR /f %%A IN (%inputfile%) do ( “%bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%” )

    Thanks one more time! But still… brackets not worked, – same empty file created. I’ve put quotes per your advice, – it even not create output file… I’ve also tried with different configuration (with quotes without brackets and vice versa) – nothing… I believe its some scripts “spelling” issue but I have no idea how to make it work…

    Avatar
    igor7
    Member

    Re: Need some help with batch script – redirect output into text file

    beddo,
    thank you for help, but script create empty output file… I played around with your script (added date and time to output file). It assume that script itsef, input and output files in the same directory:

    @echo off
    :: prepare date/time stamp
    for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%k-%%j-%%l
    for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i
    :: timestamp (ddmmmyyyy-hhmm)
    set tm=%tm::=-%
    set dtt=%dt%%tm%
    SET “bpipath=C:program filesveritasnetbackupbinadmincmd”
    SET “inputfile=tapes.txt”
    SET “outputfile=weekly-%dtt%.txt”
    IF NOT EXIST %inputfile% GOTO NEEDINPUT
    IF NOT EXIST %outputfile% GOTO CONTINUE
    echo %outputfile% already exists and will be overwritten if you continue.
    echo Press any key to continue or ctrl+c to abort
    pause
    :CONTINUE
    FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%
    GOTO END
    :NEEDINPUT
    echo This script need input file to continue, make sure %inputfile% exists
    pause
    :END
    [/CODE]

    The input file look like:
    [CODE]
    C040S2
    F217S3
    C038S2
    [/CODE]

    But for some reason, the command [CODE]FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%[/CODE]
    is not executed… As I said output file is empty.[CODE]
    @echo off
    :: prepare date/time stamp
    for /f “Tokens=1-4 Delims=/ ” %%i in (‘date /t’) do set dt=%%i-%%k-%%j-%%l
    for /f “Tokens=1” %%i in (‘time /t’) do set tm=-%%i
    :: timestamp (ddmmmyyyy-hhmm)
    set tm=%tm::=-%
    set dtt=%dt%%tm%
    SET “bpipath=C:program filesveritasnetbackupbinadmincmd”
    SET “inputfile=tapes.txt”
    SET “outputfile=weekly-%dtt%.txt”
    IF NOT EXIST %inputfile% GOTO NEEDINPUT
    IF NOT EXIST %outputfile% GOTO CONTINUE
    echo %outputfile% already exists and will be overwritten if you continue.
    echo Press any key to continue or ctrl+c to abort
    pause
    :CONTINUE
    FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%
    GOTO END
    :NEEDINPUT
    echo This script need input file to continue, make sure %inputfile% exists
    pause
    :END
    [/CODE]

    The input file look like:

    C040S2
    F217S3
    C038S2
    [/CODE]

    But for some reason, the command [CODE]FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%[/CODE]
    is not executed… As I said output file is empty.[CODE]
    C040S2
    F217S3
    C038S2
    [/CODE]

    But for some reason, the command FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%[/CODE]
    is not executed… As I said output file is empty.[CODE]FOR /f %%A IN (%inputfile%) do %bpipath%/bpmedialist -mlist -U -m %%A >> %outputfile%[/CODE]
    is not executed… As I said output file is empty.

    Avatar
    igor7
    Member

    Re: View all users who was logged into particular computer during last day

    Quote:
    There is however also an other reason to check only for the last 24 hours!

    Rems, thank you for explanation. In Israel we have DST changes twice at year, so all you said above is very important.
    I wrote some article about DST changes (it use some scripts to make DST changes on client computers) and I think I’ll post this article in Petri forum also,
    but it different story… Anyway thank you very mach for help, it’s much appreciated.

    Avatar
    igor7
    Member

    Re: View all users who was logged into particular computer during last day

    Rems;237881 wrote:
    Tehcamel’s solution to run the script like:
    cmd /c cscript.exe /nologo “scriptname.vbs” >>output.txt
    Will work fine, but only if you convert the MsgBox statement in the script to wscript.echo statements first.

    Here’s an alternative solution…

    /Rems

    Rems,
    No word…:bowdown: awesome! But in last script you missed “rem” before

    If DateDiff(“n”,LastLogon, dt)/60 =< 24 Then
    [/CODE]
    and onother one "rem" before second End if

    Otherwice outpoot has only one line:

    [CODE]
    5/12/2011 4:24:35 PM * Target computer: Kiev

    ——-
    [/CODE]

    Or probably it's simple no one was logged on during last 24 hours…;-)[CODE]
    If DateDiff(“n”,LastLogon, dt)/60 =< 24 Then
    [/CODE]
    and onother one “rem” before second End if

    Otherwice outpoot has only one line:

    5/12/2011 4:24:35 PM * Target computer: Kiev

    ——-
    [/CODE]

    Or probably it’s simple no one was logged on during last 24 hours…;-)[CODE]
    5/12/2011 4:24:35 PM * Target computer: Kiev


    [/CODE]

    Or probably it’s simple no one was logged on during last 24 hours…;-)

    Avatar
    igor7
    Member

    Re: View all users who was logged into particular computer during last day

    falbanese,
    Thank for help.
    I’ll check your solution.

    Rems,
    As always… this is it!!! Working good for remote mashine as well as for local.
    Little question… It is posiible to save otput into txt file in same directory where this script running?

    Avatar
    igor7
    Member
    in reply to: Free disk space vbscript help #295062

    Re: Free disk space vbscript help

    I’m also looking for pretty same scripting solution. My goal is to check amount of free space on 640MB ZIP disk and return to user message saying how mach free space on the drive. Already found solution…

    strComputer = “.”
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)
    Set colDisks = objWMIService.ExecQuery _
    (“Select * from Win32_LogicalDisk Where DeviceID = ‘E:'”)
    For Each objDisk in colDisks
    strDiskSize = (objDisk.FreeSpace / ( 1024 * 1024 ) )
    If strDiskSize < = 100 then
    Wscript.Echo "Not enough free space on MO disk to perfom Audit Backup"& VbCr & _
    "Please use another MO DISK."
    WScript.Quit
    End If
    Next
    Dim objWMIService, objItem, colDisks, strComputer
    On Error Resume Next
    For Each objItem in colDisks
    Wscript.Echo "Computer: " & objItem.SystemName & VbCr & _
    "" & vbCr & _
    " ==================================" & VbCr & _
    "Total Size: " & Int(objItem.Size /1048576) & " MB" & vbCr & _
    " ==================================" & VbCr & _
    "Free Space: " & Int(objItem.FreeSpace /1048576) & " MB" & vbCr & _
    " ==================================" & VbCr & _
    "Integrity check has been successfully copleted!!"
    WSCript.Quit
    Next[/CODE]

    And another one:

    [CODE]
    ::== Space.bat
    @echo off
    setLocal EnableDelayedExpansion

    for /f "tokens=3 delims= " %%A in ('dir /s/-c ^|find "File(s)"') do (
    set /a fileTOT=%%A/1048576
    )
    for /f "tokens=3 delims= " %%A in ('dir /s/-c ^|find "bytes free"') do (
    set /a FREE=%%A/1048576
    )

    echo used: !fileTOT!MB
    echo free: !FREE!MB
    set /a TOTAL=!fileTOT!+!FREE!
    echo total disk space: !TOTAL!MB
    set /a pcUSED=(!fileTOT!*100)/!TOTAL!
    echo percent used: !pcUSED!
    ::==========================
    pause[/CODE][CODE]
    strComputer = “.”
    Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)
    Set colDisks = objWMIService.ExecQuery _
    (“Select * from Win32_LogicalDisk Where DeviceID = ‘E:'”)
    For Each objDisk in colDisks
    strDiskSize = (objDisk.FreeSpace / ( 1024 * 1024 ) )
    If strDiskSize < = 100 then
    Wscript.Echo “Not enough free space on MO disk to perfom Audit Backup”& VbCr & _
    “Please use another MO DISK.”
    WScript.Quit
    End If
    Next
    Dim objWMIService, objItem, colDisks, strComputer
    On Error Resume Next
    For Each objItem in colDisks
    Wscript.Echo “Computer: ” & objItem.SystemName & VbCr & _
    “” & vbCr & _
    ” ==================================” & VbCr & _
    “Total Size: ” & Int(objItem.Size /1048576) & ” MB” & vbCr & _
    ” ==================================” & VbCr & _
    “Free Space: ” & Int(objItem.FreeSpace /1048576) & ” MB” & vbCr & _
    ” ==================================” & VbCr & _
    “Integrity check has been successfully copleted!!”
    WSCript.Quit
    Next[/CODE]

    And another one:

    ::== Space.bat
    @echo off
    setLocal EnableDelayedExpansion

    for /f “tokens=3 delims= ” %%A in (‘dir /s/-c ^|find “File(s)”‘) do (
    set /a fileTOT=%%A/1048576
    )
    for /f “tokens=3 delims= ” %%A in (‘dir /s/-c ^|find “bytes free”‘) do (
    set /a FREE=%%A/1048576
    )

    echo used: !fileTOT!MB
    echo free: !FREE!MB
    set /a TOTAL=!fileTOT!+!FREE!
    echo total disk space: !TOTAL!MB
    set /a pcUSED=(!fileTOT!*100)/!TOTAL!
    echo percent used: !pcUSED!
    ::==========================
    pause[/CODE][CODE]
    ::== Space.bat
    @echo off
    setLocal EnableDelayedExpansion

    for /f “tokens=3 delims= ” %%A in (‘dir /s/-c ^|find “File(s)”‘) do (
    set /a fileTOT=%%A/1048576
    )
    for /f “tokens=3 delims= ” %%A in (‘dir /s/-c ^|find “bytes free”‘) do (
    set /a FREE=%%A/1048576
    )

    echo used: !fileTOT!MB
    echo free: !FREE!MB
    set /a TOTAL=!fileTOT!+!FREE!
    echo total disk space: !TOTAL!MB
    set /a pcUSED=(!fileTOT!*100)/!TOTAL!
    echo percent used: !pcUSED!
    ::==========================
    pause[/CODE]

    Avatar
    igor7
    Member

    Re: Searching for file in folder named as current month using vbs script

    Thanks, Rems!! As always, it work!!!

    Avatar
    igor7
    Member
    in reply to: Writing into the text file using vbs script. #295060

    Re: Writing into the text file using vbs script.

    Rems;203582 wrote:
    x = 700

    for iCnt = 1 to x[/CODE] [/QUOTE]
    Thanks, Rems,- now my life match easier!!![CODE]x = 700

    for iCnt = 1 to x[/CODE]

    Thanks, Rems,- now my life match easier!!!

    Avatar
    igor7
    Member
    in reply to: Script for Popup Box to Accept Terms on Windows Login #295059

    Re: Script for Popup Box to Accept Terms on Windows Login

    You can use this code as logon script:

    Logon policy acceptance script

    >

    sHorizontal = “500”
    sVertical = “600”
    cnt = 60 ‘seconds before auto logoff
    Set objWMIService = GetObject _
    (“winmgmts:rootcimv2”)
    set objShell = CreateObject _
    (“WScript.Shell”)
    Set Fso = CreateObject(“Scripting.FileSystemObject”)
    Set tempfolder = Fso.GetSpecialFolder(2)
    supportingcode = tempfolder & “” & Fso.GetTempName
    Sub Window_OnLoad
    ‘Size Window
    Window.resizeTo sHorizontal,sVertical
    ‘Center window
    Set colItems = objWMIService.ExecQuery _
    (“Select * From Win32_DesktopMonitor”,,48)
    For Each objItem In colItems
    sWidth = objItem.ScreenWidth
    sHeight = objItem.ScreenHeight
    If sWidth > intHorizontal _
    then intHorizontal = sWidth
    If sHeight > intVertical _
    then intVertical = sHeight
    Next
    intLeft = (intHorizontal – sHorizontal) /2
    intTop = (intVertical – sVertical) /2
    Window.moveTo intLeft, intTop
    ‘default window content
    window.location.href=”#Top”
    ‘iTimerID = window.setInterval(“ShowSplash”, 15000)
    iTimerID = window.setInterval(“y”, 1000, “VBScript”)
    End Sub
    function y()
    Text1.innerHTML= “Time Left To Make A Decision: ” & Cnt
    cnt = cnt – 1
    If cnt < 0 then call logoff
    end function
    Sub reloadHTA()
    location.reload True
    End Sub
    Sub ShowSplash
    Splash.Style.Display = "None"
    End Sub
    Function HTA_Sleep(mSec)
    strRun = supportingcode & ".vbs"
    With Fso.OpenTextFile(strRun, 2, true)
    .WriteLine "On Error Resume Next"
    .WriteLine "Wscript.sleep wScript.Arguments(0)"
    .close
    strCommand = "cscript.exe //NoLogo " & strRun & " " & mSec
    objShell.run(strCommand), 0, True
    Fso.DeleteFile(strRun)
    End With
    End Function
    '——————————————————————-
    Sub DeclineScript( oBtt )
    sAction = "LogOff"
    oBtt.style.color = "white"
    oBtt.style.backgroundcolor = "red"
    oBtt.style.fontstyle = "italic"
    call logoff
    End Sub
    Sub logoff
    If Not sAction = "LogOn" Then
    session = objShell.ExpandEnvironmentStrings("%sessionname%")
    If UCase(session) = UCase("Console") Then session = Empty
    strCommand = "%comspec% /c %WinDir%system32logoff.exe " & session
    objShell.Run(strCommand),0 ,True
    Cleanup
    End If
    End Sub
    Sub AcceptScript( oBtt )
    sAction = "LogOn"
    oBtt.style.color = "white"
    oBtt.style.backgroundcolor = "green"
    oBtt.style.fontstyle = "italic"
    HTA_Sleep(100)
    'run vbScript from within this script:
    ' strVBS = "[URL="file://server/share/folder/file.vbs"]\serversharefolderfile.vbs[/URL]"
    ' objShell.run("cscript.exe //NoLogo " & strVBS), 0, True
    Cleanup
    End Sub
    Sub Cleanup
    Set objWMIService = Nothing
    set objShell = Nothing
    Set Fso = Nothing
    Set tempfolder = Nothing
    Self.Close()
    End Sub

    Table.Normal
    {
    font: 8.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#E9E9E9′,EndColorStr=’#9E9E9E’);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    vertical-align:;
    }

    TD.MenuNormal
    {
    font: 8.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#eeeeee’,EndColorStr=’#5e9ab9′);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    vertical-align:;
    cursor:Hand;
    }

    Body.Normal
    {
    font: 10.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#86cceb’,endColorStr=’#5589ab’);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    }


    If you want use this computer
    You need to accept following rules

    © 1985-2005 Microsoft Corporation. All rights reserved.

    • ewgsh hhxd rv hv dbvl edr hwef
      ssv vdrjsrvjeje jeyjv
    • rth rgb ughbh ht jh 456 brjtj
    • tjt fgcy byj bbby v a ryhu
    • itui gb gj 777
    • tuktu hfetygjf gg ryjgyjgrthggyj 8
    • ewgsh hhxd rv hv dbvl edr hwef
    • rth rgb ughbh ht jh 456 brjtj
    • tjt fgcy byj bbby v a ryhu
    • itui gb gj 777
    • tuktu hfetygjf gg ryjgyjgrthggyj 8
    • rgdv

     

    [/CODE]

    Save it as “Logon policy acceptance.hta” and assign it as logon script for company users.[CODE]

    Logon policy acceptance script
    <hta:application
    ApplicationName=”Logon HTA”
    SingleInstance=”Yes”
    WindowsState=”Normal”
    Scroll=”No”
    SCROLLFLAT=”No”
    Navigable=”No”
    SysMenu=”No”
    Caption=”No”
    Select=яes”
    MaximizeButton=”No”
    MinimizeButton=”No”
    BORDER = “thick”
    INNERBORDER = “yes”
    SHOWINTASKBAR=”No”
    CONTEXTMENU=”No”
    Icon = “%SystemRoot%Explorer.exe”>
    >

    sHorizontal = “500”
    sVertical = “600”
    cnt = 60 ‘seconds before auto logoff
    Set objWMIService = GetObject _
    (“winmgmts:rootcimv2”)
    set objShell = CreateObject _
    (“WScript.Shell”)
    Set Fso = CreateObject(“Scripting.FileSystemObject”)
    Set tempfolder = Fso.GetSpecialFolder(2)
    supportingcode = tempfolder & “” & Fso.GetTempName
    Sub Window_OnLoad
    ‘Size Window
    Window.resizeTo sHorizontal,sVertical
    ‘Center window
    Set colItems = objWMIService.ExecQuery _
    (“Select * From Win32_DesktopMonitor”,,48)
    For Each objItem In colItems
    sWidth = objItem.ScreenWidth
    sHeight = objItem.ScreenHeight
    If sWidth > intHorizontal _
    then intHorizontal = sWidth
    If sHeight > intVertical _
    then intVertical = sHeight
    Next
    intLeft = (intHorizontal – sHorizontal) /2
    intTop = (intVertical – sVertical) /2
    Window.moveTo intLeft, intTop
    ‘default window content
    window.location.href=”#Top”
    ‘iTimerID = window.setInterval(“ShowSplash”, 15000)
    iTimerID = window.setInterval(“y”, 1000, “VBScript”)
    End Sub
    function y()
    Text1.innerHTML= “Time Left To Make A Decision: ” & Cnt
    cnt = cnt – 1
    If cnt < 0 then call logoff
    end function
    Sub reloadHTA()
    location.reload True
    End Sub
    Sub ShowSplash
    Splash.Style.Display = “None”
    End Sub
    Function HTA_Sleep(mSec)
    strRun = supportingcode & “.vbs”
    With Fso.OpenTextFile(strRun, 2, true)
    .WriteLine “On Error Resume Next”
    .WriteLine “Wscript.sleep wScript.Arguments(0)”
    .close
    strCommand = “cscript.exe //NoLogo ” & strRun & ” ” & mSec
    objShell.run(strCommand), 0, True
    Fso.DeleteFile(strRun)
    End With
    End Function


    Sub DeclineScript( oBtt )
    sAction = “LogOff”
    oBtt.style.color = “white”
    oBtt.style.backgroundcolor = “red”
    oBtt.style.fontstyle = “italic”
    call logoff
    End Sub
    Sub logoff
    If Not sAction = “LogOn” Then
    session = objShell.ExpandEnvironmentStrings(“%sessionname%”)
    If UCase(session) = UCase(“Console”) Then session = Empty
    strCommand = “%comspec% /c %WinDir%system32logoff.exe ” & session
    objShell.Run(strCommand),0 ,True
    Cleanup
    End If
    End Sub
    Sub AcceptScript( oBtt )
    sAction = “LogOn”
    oBtt.style.color = “white”
    oBtt.style.backgroundcolor = “green”
    oBtt.style.fontstyle = “italic”
    HTA_Sleep(100)
    ‘run vbScript from within this script:
    ‘ strVBS = “[URL=”file://server/share/folder/file.vbs”]\serversharefolderfile.vbs[/URL]”
    ‘ objShell.run(“cscript.exe //NoLogo ” & strVBS), 0, True
    Cleanup
    End Sub
    Sub Cleanup
    Set objWMIService = Nothing
    set objShell = Nothing
    Set Fso = Nothing
    Set tempfolder = Nothing
    Self.Close()
    End Sub

    Table.Normal
    {
    font: 8.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#E9E9E9′,EndColorStr=’#9E9E9E’);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    vertical-align:;
    }

    TD.MenuNormal
    {
    font: 8.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#eeeeee’,EndColorStr=’#5e9ab9′);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    vertical-align:;
    cursor:Hand;
    }

    Body.Normal
    {
    font: 10.25pt Verdana;
    color:#000080;
    font-weight:bold;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0,StartColorStr=’#86cceb’,endColorStr=’#5589ab’);
    padding-top:1;
    padding-bottom:1;
    Text-Align:;
    }

    <div id="Splash" STYLE="Height:200;Width:400;Border:0.5mm solid green;
    font:14pt arial;
    filter:progid:DXImageTransform.Microsoft.Gradient
    (GradientType=0, StartColorStr=’#5589ab’, EndColorStr=’#86cceb’)
    progid:DXImageTransform.Microsoft.dropshadow(OffX=0, OffY=0,
    Color=’green’, Positive=’true’)”>

    If you want use this computer

    You need to accept following rules

    © 1985-2005 Microsoft Corporation. All rights reserved.

    • ewgsh hhxd rv hv dbvl edr hwef

      ssv vdrjsrvjeje jeyjv

    • rth rgb ughbh ht jh 456 brjtj
    • tjt fgcy byj bbby v a ryhu
    • itui gb gj 777
    • tuktu hfetygjf gg ryjgyjgrthggyj 8
    • ewgsh hhxd rv hv dbvl edr hwef
    • rth rgb ughbh ht jh 456 brjtj
    • tjt fgcy byj bbby v a ryhu
    • itui gb gj 777
    • tuktu hfetygjf gg ryjgyjgrthggyj 8
    • rgdv

     

    [/CODE]

    Save it as “Logon policy acceptance.hta” and assign it as logon script for company users.

    Avatar
    igor7
    Member
    in reply to: Create and delete share on remote computer. #295058

    Re: Create and delete share on remote computer.

    ramesh_hv,
    Thank you for post, but us I said above this script should be executed with admin privileges, otherwise it not work. The RunAS vbs script from my post resolve this problem, but it always leave RunAS.exe administrator password command prompt window open…
    I asked and I answer to myself, may be it will be useful for somebody else.
    To make sure RunAS.exe administrator command prompt window will close during main script execution need to add this code to script:

    Set oShell = CreateObject(“WScript.Shell”)
    Set oWmg = GetObject(“winmgmts:”)
    strWndprs = “select * from Win32_Process where name=’runas.exe'”
    Set objQResult = oWmg.Execquery(strWndprs)
    For Each objProcess In objQResult
    intReturn = objProcess.Terminate(1)
    Next
    [/CODE][CODE]
    Set oShell = CreateObject(“WScript.Shell”)
    Set oWmg = GetObject(“winmgmts:”)
    strWndprs = “select * from Win32_Process where name=’runas.exe'”
    Set objQResult = oWmg.Execquery(strWndprs)
    For Each objProcess In objQResult
    intReturn = objProcess.Terminate(1)
    Next
    [/CODE]

    Avatar
    igor7
    Member

    Re: How to Open a Intranet Windows Authenticated Website using vbs script?

    OK, guys. I did some reverse engineering staff and finally I’ve find solution for my problem! First of all I understand that this is not IIS configuration problem. IIS configured to use Integrated Windows Authentication, so each AD network resource should be accessed without providing username/password. In my case username/password prompt appears because the site I trying to access placed on server in other (trusted) domain. How I know this? Well, when I followed to Virtual advice:

    Quote:
    Tools >> Internet Options >> Click on the ‘security tab’ and then highlight ‘Local Intranet’. Click on ‘Sites’ >> ‘advanced’ >> add your intranet web url in to there. Next, click on ‘custom settings’ at the bottom whilst ensuring ‘local intranet’ is still highlighted. Scroll to the bottom and make sure there is a dot in ‘Automatic logon with current username and password, under the logon section.

    and than open the particular web site, before it opens (without username/password prompt) the following message is appears:

    Code:
    This page is accessing information that is not under its control.
    This poses a security risk. Do you want to continue?

    I searched the web for understand the reason why this message is appears and find explanation in msdn site:

    Quote:
    This is how cross-domain security fundamentally works. It’s far from a perfect system, but it’s simple. Since there is no way to specify which pages trust other pages to access their data, Internet Explorer simply says that if two pages are not in the same domain, they cannot communicate. More precisely, Zone Manager (found on the security tab in Internet Settings) does allow the user to say that a page may access another page, but as you point out, most people leave it set on prompt. You can suggest users add the page to the trusted site zone, or merely say Yes to the dialog box…

    So, as we see the way to avoid security notification message is add the web site to trusted sites zone. I did so and when next time I opened this site it doesn’t prompt me for username/password! But still this solution doesn’t meet my needs… I don’t want to configure IE on each computer manually before accessing this particular web site. To be honest it can be configured trough registry or with a *.reg file. I found Internet Explorer security zones registry entries for advanced users site with perfect explanation about IE zones and authentication methods. But since I’ve promised to our users “script this issue”, I keep my promise and wrote the vbs script based on example from Scripting Guy website. Here is the code:

    Code:
    [FONT=Verdana][COLOR=#555a5f][COLOR=#555a5f][FONT=Verdana]On Error Resume Next[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]Const HKEY_CURRENT_USER = &H80000001[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]strComputer = “.”[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]Set objReg=GetObject(“winmgmts:\” & strComputer & “rootdefault:StdRegProv”)[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]strKeyPath = “SoftwareMicrosoftWindowsCurrentVersionInternet Settings” _[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]& “ZoneMapDomainsmysite.com”[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]objReg.CreateKey HKEY_CURRENT_USER, strKeyPath[/FONT][/COLOR]
    [COLOR=#555a5f][FONT=Verdana]strValueName = “http”[/FONT][/COLOR]
    [FONT=Verdana][COLOR=#555a5f]dwValue = 2[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue[/COLOR][/FONT]

    [FONT=Verdana][COLOR=#555a5f]Dim objShell, RegLocate, RegLocate1[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]Set objShell = WScript.CreateObject(“WScript.Shell”)[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]On Error Resume Next[/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]RegLocate = “HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsCurrentVersionInternet SettingsZones21A00″[/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]objShell.RegWrite RegLocate,”00000”,”REG_DWORD”[/FONT][/COLOR]

    [FONT=Verdana][COLOR=#555a5f]Set wshShell = WScript.CreateObject (“WSCript.shell”) [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]Set IE = CreateObject(“InternetExplorer.Application”) [/COLOR][/FONT]
    [FONT=Verdana][COLOR=#555a5f]IE.visible = 1 [/COLOR][/FONT]
    [COLOR=#555a5f][FONT=Verdana]IE.navigate(http://www.mysite.com)[/FONT][/COLOR]
    [/COLOR][/FONT]

    That’s all! Thank you guys for help! May be this information will help to somebody else…

    P.S. Tools -> Advanced -> Enable Integrated Windows Authentication (Under the security padlock icon). – is checked by default in IE 6 and 7.

    Avatar
    igor7
    Member

    Re: How to Open a Intranet Windows Authenticated Website using vbs script?

    vonPryz;152170 wrote:
    The problem you describe is exactly what integrated logon is supposed to solve. You don’t type your password each time when accessing network shares or launching Outlook, do you?

    Yes, I not typing my domain credentials to access any network resources and I agree with fact that IE can be configured to prompt username & password or automatic logon… I don’t have access to ISS configuration so I not sure with authentication method is used (btw here is explanation about this).
    But still as I said I’m use many computer station to log on into company network environment so I prefer have an script rather then configure each station

    Avatar
    igor7
    Member

    Re: How to Open a Intranet Windows Authenticated Website using vbs script?

    Thank you guys for the replays, but I don’t think that IE configuration problem… I think IIS configured to promt username/password for each connection to this web site.
    I’m in vacation now till the end of this week, so I can’t try what you advised. But even it can be configured trough IE settings it doesn’t help me much, because in my work place I use multiple computer station to log in into company network, so I prefer to use username/password prompt rather configure each station I use. That’s why I’m searching for the script.

Viewing 30 posts - 1 through 30 (of 66 total)