Jump to content

Toggle minimize/restore CMD Window with a VBScript?


Recommended Posts

On 6/10/2018 at 7:37 PM, gunsmokingman said:

I did a test of cmd.exe using Sendkeys I did manage to get something

to work. The problem is the loop for cmd.exe it just stays stuck in the

loop. 

But seemingly you tested *everything* BUT the ALT+SPACE combo (i.e. the one needed and that doesn't seem to work on cmd.exe, it seemingly works just fine on - say - notepad).

Maybe a wrapper *like* Conemu is needed (but not applicable to the OP situation) :unsure:

jaclaz

Link to comment
Share on other sites


It may depend on the OS. ALT+Space does work on the CMD on the Windows 7 32bit that I tested on.

Is what is displayed in the CMDs even important? Because if not, you can just put up a "please wait" message, and run those CMDs minimized so that they do not appear at all.

Link to comment
Share on other sites

10 minutes ago, Tripredacus said:

It may depend on the OS. ALT+Space does work on the CMD on the Windows 7 32bit that I tested on.

Is what is displayed in the CMDs even important? Because if not, you can just put up a "please wait" message, and run those CMDs minimized so that they do not appear at all.

Did you try the actual sctipts? :dubbio:

The ALT+Space (actual keys) do work on all windows, it is the wscript SendKeys method that doesn't work here, for CMD.EXE only.

jaclaz

 

Link to comment
Share on other sites

I think I have to give up :(, but I will try yet another time,

Sending *any* keys/text via sendkeys works just fine on cmd.exe here, including commands like dir, echo, etc. BUT the sequence  (via Sendkeys) ALT+SPACE DOES NOT.

If I issue a ALT SPACE I (italian equivalent for the english ALT SPACE N) I obtain a space an a I on the command line.

Still here, the SAME sendkeys script to *another* window (I tried Notepad) works just fine with ALT+SPACE.

FINAL recap:

The OP may get away with his request by issuing a ALT SPACE N (or I, etc, as said this is language dependent), so the only interesting thing is to succeed in specifically sending to cmd,exe specifically ALT SPACE N, so anyting else (that is working just fine) doesn't matter.

With "normal" keyboard keypresses just entering ALT and space opens the dropdown box, and then the following letter is the choice.

With sendkeys (as said here at least) sending ALT and space does not, it simply adds a space on the command line.

jaclaz

 

 

 

Link to comment
Share on other sites

To recap jaclaz all you have offer is nothing other than some apps that OP did not want to use.

1:\ The only way you might be able to do this is with VBS sendkeys method

https://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx

This means, it might work or it might not work

No where does it say it will work or that this is the only way of doing it.

2:\ I have given the OP a solution to his problem that he elected not to use

Quote

Mike88 if you want a simple way to do what you want could you run the cmd from vbs

Example

[CODE}

Dim Act :Set Act = CreateObject("Wscript.Shell")
'-> First Cmd Show Windows Wait Until Finished
 Act.Run("Some1.cmd /Switches"),1,True 
'-> Second Cmd Hide Windows Wait Until Finished
 Act.Run("Some2.cmd /Switches"),0,True 
 '-> Third Cmd Show Windows Wait Until Finished
 Act.Run("Some3.cmd /Switches"),1,True 

{/CODE]

3;\  Then I provided the list from here https://technet.microsoft.com/en-us/library/ee156605.aspx

Integer = Window Style Description

0 = Hides the window and activates another window.

1 = Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

2 = Activates the window and displays it as a minimized window.

3 = Activates the window and displays it as a maximized window.

4 = Displays a window in its most recent size and position. The active window remains active.

5 = Activates the window and displays it in its current size and position.

6 = Minimizes the specified window and activates the next top-level window in the Z order. The Z order is nothing more than the list detailing the order in which windows are to be activated. If you press ALT+TAB, you will see a graphical representation of the Z list.

7 = Displays the window as a minimized window. The active window remains active.

8 = Displays the window in its current state. The active window remains active.

9 = Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

10 = Sets the show-state based on the state of the program that started the application.

4:\ Sendkeys does work in cmd perhaps it does not accept all keys combination. Myself I

only use sendkey for demo and nothing else more. 

	'-> Objects For Script Run Time
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Run Time
Dim UP  :UP = Act.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\Test.txt"
Dim UN  :UN = Act.ExpandEnvironmentStrings("%UserName%")
'-> Open Cmd 
 Act.Run("cmd.exe"),1,False 
 Act.AppActivate("cmd.exe") :WScript.Sleep 100  
'-> Body Of Command For Cmd
 Act.SendKeys "Echo Off" :WScript.Sleep 100
 Act.SendKeys "{ENTER}"
 Act.SendKeys "CLS && Color A9" :WScript.Sleep 100
 Act.SendKeys "{ENTER}"
 Act.SendKeys "" :WScript.Sleep 1000
 Act.SendKeys "{ENTER}"
 Act.SendKeys "Echo="+UN+" > " + UP
 Act.SendKeys "{ENTER}"
 Act.SendKeys "CLS && Color F9" :WScript.Sleep 1000
 Act.SendKeys "{ENTER}"
 Act.SendKeys "" :WScript.Sleep 100
 Act.SendKeys "{ENTER}"
 Act.SendKeys "Dir /b" :WScript.Sleep 1000
 Act.SendKeys "{ENTER}"
 Act.SendKeys "Dir /b >>" + UP:WScript.Sleep 100
 Act.SendKeys "{ENTER}"
 Act.SendKeys "Exit" :WScript.Sleep 3500
 Act.SendKeys "{ENTER}"
'-> Check To See If Text Exist
  If Fso.FileExists(UP) Then 
'-> Open Text File
   Act.Run(UP),1,True  
'-> Ask To Keep Or Delete Text File
   If MsgBox("Yes To Delete No To Keep File",4132,"Keep Or Delete") = 6 Then 
    Fso.DeleteFile(UP),True
   End If
  End If
	

 

Link to comment
Share on other sites

To recap, I offered what I had, and tested one of the possible solutions (wscript sendkeys as they are said everywhere to be able to do that) and found out that for *some reason* the method doesn't work specifically for sending an ALT SPACE LETTER specifically to cmd.exe.

So the sendkeys method that generically works just fine specifically doesn't work (at least here), so it does not represent a possible solution (unless there is some trick to have it working for the specific task).

jaclaz

Link to comment
Share on other sites

  • 1 month later...

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...