undesirable .bat file side effects in Win7 pro 64-bit

Page 1 of 2 12 LastLast

  1. Posts : 5
    win 7 64-bit
       #1

    undesirable .bat file side effects in Win7 pro 64-bit


    I run a very simple .bat file every 5 mins:

    @echo OFF
    cd c:\user_name_directory
    mkdir foo
    exit

    I also run a similar .bat file to remove the foo directory:
    @echo OFF
    cd c:\user_name_directory
    rmdir foo
    exit

    I use task scheduler to schedule and execute each task, with each task being separated by about 2 mins, so the directory is first created, then two min later is is removed, and the loop repeats.

    When either task runs, I get a window that flashes up on the screen and then instantaneously disappears. I can't tell what window it is, but I suspect it is the Command prompt, e.g. DOS window.

    In any case, can someone tell me how to eliminate the flashing window side effect??

    Thank you!
      My Computer


  2. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #2

    Hi threejeeps and welcome to W7 Forums

    That is an unfortunate side effect of invoking the command console.

    Try the following vbscript files instead:

    Code:
    strFolder = "C:\test"
    set objFSO = createobject ("Scripting.FileSystemObject")
    if objFSO.FolderExists (strFolder) = False then
    objFSO.CreateFolder strFolder
    else
    objFSO.DeleteFolder strFolder
    end if
    This code carries out both the creation and deletion of a folder, alternating with each execution cycle. If you require explicitly separate files for each function, use the following pieces of code:

    Create Folder:
    Code:
    strFolder = "C:\test"
    set objFSO = createobject ("Scripting.FileSystemObject")
    objFSO.CreateFolder strFolder
    Delete Folder:
    Code:
    strFolder = "C:\test"
    set objFSO = createobject ("Scripting.FileSystemObject")
    objFSO.DeleteFolder strFolder
    Last edited by Dwarf; 19 Jun 2012 at 23:58.
      My Computer


  3. Posts : 5
    win 7 64-bit
    Thread Starter
       #3

    So I tried the two vbs script version (the delete is giving an error):
    Delete Folder
    Code:
    strFolder = "C:\test" set objFSO = createobject("Scripting.FileSystemObject") objFSO.DeleteFolder strFolder

    I changed strFolder to: "C:\user_name\my_test"

    I get an error reported when it runs: Line 3, Char 1, Path not found, 800a004c, VBScript runtime error.

    Any idea as to why??

    Thanks
      My Computer


  4. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #4

    I've just checked the code on my system, and all scripts run as expected. Check your typing again. I think you have omitted a space character.

    What you have written:
    set objFSO = createobject("Scripting.FileSystemObject")

    What you should have written (notice the space before the ():
    set objFSO = createobject ("Scripting.FileSystemObject")
      My Computer


  5. Posts : 5
    win 7 64-bit
    Thread Starter
       #5

    Yes, you are correct. I omitted the space. Thank you.

    I have a related question. Is there a way using a VB script to do a ping of a IP address and send the results into a file?

    Thanks

    John
      My Computer


  6. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #6

    Glad you have got that sorted. :)

    It is possible to do what you wish, however it involves creating 2 files. The first one is a vbscript file which suppresses the command window and then calls a batch file which actually executes the command.

    VBScript File:
    Code:
    Set WshShell = CreateObject("WScript.Shell") 
    WshShell.Run chr(34) & "<PATH>.bat" & Chr(34), 0
    Set WshShell = Nothing
    <PATH> should be edited to point to the location of the following batch file.

    Batch File:
    Code:
    ping 173.194.67.94 > <PATH>\pingresult.txt
    <PATH> should be edited to point to the location where you want to store the results. The filename can be changed if desired. Obviously, you will need to substitute the required IP in place of what I have included (which is Google.co.uk). You can check functionality by executing the batch file separately, if you wish.
      My Computer


  7. Posts : 784
    Linux Mint 17 Cinnamon | Win 7 Ult x64
       #7

    threejeeps said:
    I run a very simple .bat file every 5 mins:

    In any case, can someone tell me how to eliminate the flashing window side effect??

    Thank you!
    Sorry to jump in here. Not meaning to detract from the help that has already been provided, but I'm sure I don't have this this issue. I have tasks running regularly across multiple W7 computers and the DOS window does not flash up on any of them.

    I achieved this using the combination of settings as shown on the attached image.

    Tanya
    Attached Thumbnails Attached Thumbnails undesirable .bat file side effects in Win7 pro 64-bit-sf-1.jpg  
      My Computer


  8. Posts : 6,285
    Windows 10 Pro X64
       #8

    Does you scheduled task launch a batch file? You don't show the action tab.
      My Computer


  9. Posts : 784
    Linux Mint 17 Cinnamon | Win 7 Ult x64
       #9

    Ztruker said:
    Does you scheduled task launch a batch file? You don't show the action tab.
    Yes, sorry, it does the following (I've changed the user names)
    This one runs from the server..

    net user xxxxxx /times:m-f,su,9am-3am;Sa,9am-2am
    net user xxxxx/times:m-f,Su,9am-3am;Sa,9am-2am
    net user "zzzzzz yyyyyy" /times:m-su,9am-1am
    net user xxxxxx /times:m-Su,9am-1am
    shutdown /t 60 /s

    There's are different versions for different times of the year, but you get the gist.

    This one runs from each client computer every two hours...

    netsh interface ip set address name="Local Area Connection" dhcp
    netsh interface ip set dns name="Local Area Connection" source=dhcp

    This helps stop the boys from trying to configure their way around network security
      My Computer


  10. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #10

    I've had a further look into this, and there is a way to do what you want. At the moment, I have the results displayed on the screen, but I'll see what I can do about that.

    Here are the blocks of code I used to test. They are identical, apart from the strIP variable (the IP address that is being queried).

    Again, I have used Google.co.uk for this example. It returns 0 and True as the results.
    Code:
    strIP = "173.194.67.94"
    wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strIP & "'"
    Set objWMIService = GetObject ("winmgmts://./root/cimv2")
    Set objPing = objWMIService.ExecQuery (wmiQuery)
    For Each objStatus in objPing
    msgBox objStatus.Statuscode
    strPingResult ="True"
    If IsNull (objStatus.Statuscode) Or objStatus.Statuscode <> 0 Then strPingResult = "False"
    msgBox strPingResult
    Next
    This IP address does not exist. Consequently, the routine returns 11010 and False.
    Code:
    strIP = "123.45.67.89"
    wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strIP & "'"
    Set objWMIService = GetObject ("winmgmts://./root/cimv2")
    Set objPing = objWMIService.ExecQuery (wmiQuery)
    For Each objStatus in objPing
    msgBox objStatus.Statuscode
    strPingResult ="True"
    If IsNull (objStatus.Statuscode) Or objStatus.Statuscode <> 0 Then strPingResult = "False"
    msgBox strPingResult
    Next
    In both cases, the first output is the raw data, which corresponds to the information found in the section StatusCode here: Win32_PingStatus class

    The second output returns True if the raw data exists and is 0, and False if it doesn't exist or is non-zero.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:18.
Find Us