Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: winscript help  (Read 6077 times)

0 Members and 1 Guest are viewing this topic.

bil

  • Guest
winscript help
« on: October 09, 2005, 01:21:03 PM »
ok im trying to learn winscript its goin alright but i need some help with something

ok this batch code makes 100 command promts open is there a way to do this with a vbs

for /L %%v in (1,1,100) do start

thanks


bil

  • Guest
Re: winscript help
« Reply #1 on: October 09, 2005, 01:23:37 PM »
another thing i cant find a good site to learn winscript on does anyone know where one is

thanks again

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: winscript help
« Reply #2 on: October 09, 2005, 05:51:18 PM »
Why anyone would need to do this is beyond me. Try learning about the power and versatility of Windows Script before you attempt such childish games.

Windows Script Host

Code: [Select]

Set WshShell = CreateObject("WScript.Shell")
For i = 1 to 100
     WshShell.Run "c:\windows\system32\Cmd.exe"
Next


Not withstanding all the "Dummy" books, script writing requires some logical thought.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

bil

  • Guest
Re: winscript help
« Reply #3 on: October 09, 2005, 07:36:43 PM »
ok i need some help understanding this line im trying to put the file name now4.vbs in this but i dont know how to put it in the script looks like this

If InStr(objFile.FileName, "current") Then


where would i add the file name thanks

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: winscript help
« Reply #4 on: October 10, 2005, 07:53:55 AM »
Looking a one line of code is difficult at best and your question is very vague.

First you need to create a reference to the FileSystemObject.

Set fso = CreateObject("Scripting.FileSystemObject")

Next you need a reference to the file.

Set objFile = fso.GetFile("now4.vbs") ' You can put a path on the file name

Your IF statement is in error. There is no FileName property for the file object; use objFile.Name

Now it becomes problematic. If your are looking for the string current within the file label you're not going to find it (in this case) but if you're looking in the files contents you can either read the entire contents of the file with the ReadAll method or read the file line by line. The method for inserting a line in a sequential file is dependent on where the insertion point is... beginning of file, end of file or somewhere in the middle.

Good luck.  8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

bil

  • Guest
Re: winscript help
« Reply #5 on: October 12, 2005, 12:59:38 PM »
yea i didnt post the rest of the script b/c i couldnt find it or havent wrote it so here it is

bil

  • Guest
Re: winscript help
« Reply #6 on: October 12, 2005, 01:00:42 PM »
opps forgot to add it
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
   ("ASSOCIATORS OF {Win32_Directory.Name='T:\Act'} Where " _
       & "ResultClass = CIM_DataFile")

For Each objFile In colFileList
   If InStr(objFile.FileName, "current") Then
       objFile.Delete
   End If
Next



Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: winscript help
« Reply #7 on: October 12, 2005, 04:10:06 PM »
[sigh]

Using WMI to delete a file is a bit of overkill, but what the *censored*.

Code: [Select]

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
   ("ASSOCIATORS OF {Win32_Directory.Name='T:\Act'} Where " _
  & "ResultClass = CIM_DataFile")

For Each objFile In colFileList
   If InStr(objFile.FileName, "current") Then
      objFile.Delete objFile.FileName & "." & objFile.Extension
   End If
Next

It warms my heart to see someone taking advantage of the available Windows tools (especially since they are free!).

Good luck.  8)
« Last Edit: October 12, 2005, 04:37:14 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

bil

  • Guest
Re: winscript help
« Reply #8 on: October 14, 2005, 11:02:18 AM »
ok where would i add the file name i want to delete in this like if i wanted to dlete now.vbs how would i put ti in i no im suppose to add it somewhere in here i no stupid question but i dont no

For Each objFile In colFileList
   If InStr(objFile.FileName, "current") Then
  objFile.Delete

bil

  • Guest
Re: winscript help
« Reply #9 on: October 14, 2005, 11:03:26 AM »
ok where would i add the file name i want to delete in this like if i wanted to dlete now.vbs how would i put ti in i no im suppose to add it somewhere in here i no stupid question but i dont no

For Each objFile In colFileList
   If InStr(objFile.FileName, "current") Then
  objFile.Delete

bil

  • Guest
Re: winscript help
« Reply #10 on: October 14, 2005, 11:06:19 AM »
ok i no this is a stupid question  but i need help ok i dont know where to put in the file name of which i want it to dlete. i want to dlete now.vbs but i dont know where to add the name into the script i know it goes osmewhere in here but i dont know where

For Each objFile In colFileList
   If InStr(objFile.FileName, "current") Then
  objFile.Delete

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: winscript help
« Reply #11 on: October 15, 2005, 09:03:30 AM »
You don't need to specify a file name. The script as written is going out to the t:\act directory and creating a collection of all the file names.

The IF statement checks if the string "current" is present in the file name and deletes it using:

objFile.Delete objFile.FileName & "." & objFile.Extension

Be careful, the WMI service is both complex and powerful.

8)

Note: Using the FileSystemObject would have been easier and more strightforward.
« Last Edit: October 15, 2005, 09:04:57 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein