wsh

vbscript code to read input from text file avoiding manual efforts

微笑、不失礼 提交于 2019-12-02 11:33:57
I am drilling down Internet to get Vbscript code, where input is read from text file one per line and pass it to the commands in script. I am just a beginner and need help with this. Basically I am gathering script to get pending patches of servers in our environment. The script looks like below: '# '# ServerPendingUpdates.vbs '# '# Usage: cscript ServerPendingUpdates.vbs {servername} {servername} {servername} {servername} '# If no {servername} specified then 'localhost' assumed '# '# To do: Error handling '# Option Explicit Dim strServer : strServer = GetArgValue(0,"localhost") '# '# Loop

How to send Alt+space to console window?

試著忘記壹切 提交于 2019-12-02 11:22:10
问题 import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("Command Prompt") shell.SendKeys("%{ }") # This #shell.SendKeys("% ") # and this #shell.SendKeys("%( )") # and this is not working WScript is not mandatory, you can propose any programmatic solution. 回答1: Scan codes (56 and 57) are required: from win32api import * from win32con import * keybd_event(VK_LMENU, 56, 0, 0) keybd_event(VK_SPACE, 57, 0, 0) keybd_event(VK_SPACE, 57, KEYEVENTF_KEYUP, 0) keybd

Make sendKeys faster

China☆狼群 提交于 2019-12-02 09:04:44
问题 I'm trying to create a program that will open "command prompt" and open a specific port using "sendKeys". Here is my code: Set Keys = CreateObject("WScript.Shell") oShell.ShellExecute "cmd.exe","runas", 1 Sleep(0.01) Keys.sendKeys "{ENTER}" Sleep(0.01) Keys.sendKeys "rem Open TCP Port 407 inbound and outbound" Keys.sendKeys "{ENTER}" Keys.sendKeys "netsh advfirewall firewall add rule name=""EXAMPLE"" dir=out action=allow protocol=TCP localport=407" Keys.sendKeys "{ENTER}" Keys.sendKeys "netsh

can I run vbscript commands directly from the command line (i.e. without a vbs file)?

佐手、 提交于 2019-12-02 07:42:25
问题 In Python you are not obliged to use a file, you can specify -c "..." and gives the Python commands to the Python interpreter via a string on the command line. Can I achieve the same result with vbscript? I've seen solutions that need you to use a batch script, But what if I am on a system with zero writing permissions? Following the answer from @Syberdoor, I can run this: mshta vbscript:Execute("dim result:result=InputBox(""message"",""title"",""input"")(window.close):echo result") but it

Creating Shortcut where folder name is having unicode characters

大憨熊 提交于 2019-12-02 07:36:49
I have been using the below code to create shortcuts dynamically. But the targetPath throws Argument exception when the folder name has unicode characters like Thai,greek language. IWshRuntimeLibrary.WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation); shortcut.Description = "My shortcut description"; // The description of the shortcut shortcut.WorkingDirectory = currentPath; shortcut.TargetPath = targetFileLocation; // The path of the file that will launch when the shortcut is run shortcut.Save(); Reference Shell32.dll from file system

can I run vbscript commands directly from the command line (i.e. without a vbs file)?

冷暖自知 提交于 2019-12-02 07:23:48
In Python you are not obliged to use a file, you can specify -c "..." and gives the Python commands to the Python interpreter via a string on the command line. Can I achieve the same result with vbscript? I've seen solutions that need you to use a batch script, But what if I am on a system with zero writing permissions? Following the answer from @Syberdoor, I can run this: mshta vbscript:Execute("dim result:result=InputBox(""message"",""title"",""input"")(window.close):echo result") but it still doesn't print the result in the console. Syberdoor There is one trick you can possibly use and that

Change Console Title with vbscript

…衆ロ難τιáo~ 提交于 2019-12-02 05:33:21
is there a way to change the cmd title? I wrote a vbs program. But the dos title is bad. The name ist c:\windows\system32\cscript.exe I try it with: title the_name and title ="name" But both doesn't works. Thanks for help. Unfortunately you cannot do that from within the script using any of the WSH objects. The only way to do it is to launch the script via an intermediary (a .bat using the TITLE command or another script using a %comspec% argument). @AlexK The link you point to actually shows how you CAN change the title of the command window so I'm not sure why that doesn't work as a solution

Make sendKeys faster

别等时光非礼了梦想. 提交于 2019-12-02 04:27:26
I'm trying to create a program that will open "command prompt" and open a specific port using "sendKeys". Here is my code: Set Keys = CreateObject("WScript.Shell") oShell.ShellExecute "cmd.exe","runas", 1 Sleep(0.01) Keys.sendKeys "{ENTER}" Sleep(0.01) Keys.sendKeys "rem Open TCP Port 407 inbound and outbound" Keys.sendKeys "{ENTER}" Keys.sendKeys "netsh advfirewall firewall add rule name=""EXAMPLE"" dir=out action=allow protocol=TCP localport=407" Keys.sendKeys "{ENTER}" Keys.sendKeys "netsh advfirewall firewall add rule name=""EXAMPLE"" protocol=TCP dir=out localport=407 action=""allow"""

How to send Alt+space to console window?

泪湿孤枕 提交于 2019-12-02 04:05:19
import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("Command Prompt") shell.SendKeys("%{ }") # This #shell.SendKeys("% ") # and this #shell.SendKeys("%( )") # and this is not working WScript is not mandatory, you can propose any programmatic solution. Scan codes (56 and 57) are required: from win32api import * from win32con import * keybd_event(VK_LMENU, 56, 0, 0) keybd_event(VK_SPACE, 57, 0, 0) keybd_event(VK_SPACE, 57, KEYEVENTF_KEYUP, 0) keybd_event(VK_LMENU, 56, KEYEVENTF_KEYUP, 0) Generoso Montemayor I think it is a bug in windows. Here is an example

Create a shortcut with parameters added to the program path

一曲冷凌霜 提交于 2019-12-02 01:46:47
Here's the code, it works if I right click on the new .Lnk and remove the quotes from "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate" to C:\Windows\System32\control.exe /name Microsoft.Windowsupdate echo off Cls set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs" echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT% echo sLinkFile = "%USERPROFILE%\Desktop\Weekly Maintenance\Windows Update.lnk" >> %SCRIPT% echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT% echo oLink.TargetPath = "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate" >>