Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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


19 Jun 2012   #1

win 7 64-bit
 
 
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 System SpecsSystem Spec
.

19 Jun 2012   #2

Windows 8.1 Pro RTM x64
 
 

Hi threejeeps and welcome to Windows 7 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
My System SpecsSystem Spec
19 Jun 2012   #3

win 7 64-bit
 
 

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 System SpecsSystem Spec
.


19 Jun 2012   #4

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
20 Jun 2012   #5

win 7 64-bit
 
 

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 System SpecsSystem Spec
20 Jun 2012   #6

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
20 Jun 2012   #7

Linux Mint 17 Cinnamon | Win 7 Ult x64
 
 

Quote   Quote: Originally Posted by threejeeps View Post
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 Windows 7 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 Images
 
My System SpecsSystem Spec
20 Jun 2012   #8

Windows 8 Core X64
 
 

Does you scheduled task launch a batch file? You don't show the action tab.
My System SpecsSystem Spec
21 Jun 2012   #9

Linux Mint 17 Cinnamon | Win 7 Ult x64
 
 

Quote   Quote: Originally Posted by Ztruker View Post
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 System SpecsSystem Spec
21 Jun 2012   #10

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools




Our Sites

Site Links

About Us

Find 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 01:18 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33