Jump to content

Recommended Posts

Posted

hello everyone, i know zip about programming but i need to do 1 task which i think that would be done by programming in VB or VBS.

i want to put one CMD command in a simple Script maybe, which every time that i double click on it, just that CMD command run. i think that would be and interface or simple script to tell to CMD to run this command.

anyone can help in this matter?!

THANX a lot B)


Posted

hi

what should i explain? i mean i need just a simple script that contain a simple CMD command which everytime i click on that script, the command run and then close the windows, and i get the result in output file.

Posted

hi

what should i explain? i mean i need just a simple script that contain a simple CMD command which everytime i click on that script, the command run and then close the windows, and i get the result in output file.

Posted

Try This It A Simple Directory Cmd

Save it as Dir.vbs Hope this is what

you wanted.

Dim Act : Set Act = CreateObject("Wscript.Shell")

Sd = Act.ExpandEnvironmentStrings("%systemdrive%")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Cmd = ("%comspec% /T:9a /c TITLE Check For Folder | cls && Mode 75,25 && Color 9e && dir >>"& SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "Here Is The Cmd Script"

    WF.WriteLine Cmd

    WF.Close

  Act.run(Sd & "\Temp.txt")

  wscript.sleep 3000

  Fso.DeleteFile(Sd & "\Temp.txt")

Posted

Here I will try and break it down what this code does

1:\ This is a Visual Basic Script or VBS for short

2:\ It is saying I am going to start a Command Promt and output

the script to a text file

Cmd = ("%comspec% /T:9a /c TITLE Check For Folder | cls && Mode 75,25 && Color 9e && dir >>"& SD & "\Temp.txt")

3:\It then start the Command Promt with this line

Act.Run(Cmd), 1, True

4:\ Then after the Command Promt Has Completed Then I have It

Use VBS

The Set Is to shorten Down This CreateObject("Scripting.FileSystemObject")

Set Fso = CreateObject("Scripting.FileSystemObject") To Just Fso.OpenTextFile

Which Uses This Class to open the text file made in the Command Promt and

add the extra lines of text.

5:\ The script then uses the built in sleep function to rest for 3 seconds

wscript.sleep 3000

6:\ It then uses the CreateObject("Scripting.FileSystemObject") to delet the file.

Orange Is The New Name For The Action Part Of the Command Promt

The Advantage of this is it saves a lot of typing.

You can use any of Command Promt Built In Functions In this Script.

Just Change This dir to any of it functions

try Ver

Dim Act : Set Act = CreateObject("Wscript.Shell")

Sd = Act.ExpandEnvironmentStrings("%systemdrive%")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Cmd = ("%comspec% /T:9a /c TITLE Check For Folder | cls && Mode 75,25 && Color 9e && dir >>"& SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "Here Is The Cmd Script"

    WF.WriteLine Cmd

    WF.Close

  Act.run(Sd & "\Temp.txt")

  wscript.sleep 3000

  Fso.DeleteFile(Sd & "\Temp.txt")

This One I Have Added 3 More Command Promt Functions To It.

Save This As Cmd.vbs

Dim Act : Set Act = CreateObject("Wscript.Shell")

Sd = Act.ExpandEnvironmentStrings("%systemdrive%")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Cmd = ("%comspec% /T:9a /c TITLE Check For Folder | cls && Mode 75,25 && Color 9e && Dir >>"& SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "Here Is The Dir Script"

    WF.WriteLine Cmd

    WF.WriteLine "Next"

    WF.Close

Cmd = ("%comspec% /T:9a /c TITLE Check The Windows Version | cls && Mode 75,25 && Color 9e && Ver >> "  & SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "The Windows Version"

    WF.WriteLine Cmd

    WF.WriteLine "Next"

    WF.Close

Cmd = ("%comspec% /T:9a /c TITLE Check The Time | cls && Mode 75,25 && Color 9e && Time /t >>" & SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "The Time Of The Script"

    WF.WriteLine Cmd

    WF.WriteLine "Next"

    WF.Close

Cmd = ("%comspec% /T:9a /c TITLE Check The Date | cls && Mode 75,25 && Color 9e && Date /t >>" & SD & "\Temp.txt")

Act.Run(Cmd), 1, True

Set WF = Fso.OpenTextFile( Sd & "\Temp.txt", 8,true)

    WF.WriteLine "The Date Of The Script"

    WF.WriteLine Cmd

    WF.WriteLine "Next"

    WF.Close

  Act.run(Sd & "\Temp.txt")

  wscript.sleep 3000

  Fso.DeleteFile(Sd & "\Temp.txt")

Hope This Helps

Posted

by the way how can i learn to write VBScript for myself? i mean it's easy or not? cuz i recently finished my MCSE and i like to write script for network as needed.

thanks for ur advice ;)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...