windows-scripting

SETLOCAL ENABLEDELAYEDEXPANSION causes CD and PUSHD to not persist

耗尽温柔 提交于 2019-12-01 17:01:10
问题 I am trying to use setlocal enabledelayedexpansion and cd together in a batch script, which seems to not persist changes back to shell. The reason I need setlocal enabledelayedexpansion is that I need the variables in the script to be expanded dynamically upon runtime of the script. Consider the below sample batch file : a.bat ================================ setlocal enabledelayedexpansion cd .. The above batch file does not migrate to previous directory as expected ! Check this. 回答1: The

WScript.CreateObject crashes Windows Scripting Host when event handler prefix is specified for WinHTTPRequest

假装没事ソ 提交于 2019-12-01 13:40:49
According to the MSDN documentation WinHTTPRequest has four event handlers which should be accessible by specifying an event handler prefix. Unfortunately, doing so causes Windows Scripting Host to crash. The following code crashes Windows Scripting Host: Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1", "oHTTP_" ) This code works just fine: Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1" ) Any thoughts as to why? It's not part of the specification in any way. Wishful programming rarely works. Creates and returns a reference to an Automation object. CreateObject

How to stop a vb script running in windows

断了今生、忘了曾经 提交于 2019-11-30 09:58:23
I'm using windows 7 I wrote a script to check whether My Laptop is running in Battery or AC current. I googled it and succedded in that. dim a a=1 Do While a=1 If IsLaptop( "." ) Then ' WScript.Echo "Laptop" Else ' WScript.Echo "Desktop or server" End If Loop Function IsLaptop( myComputer ) On Error Resume Next Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" ) Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 ) IsLaptop = False For Each objItem in colItems if objItem.BatteryStatus=2 and objItem.EstimatedChargeRemaining=98 then WScript.Echo

When to choose development of a PowerShell Module over PowerShell Script

谁都会走 提交于 2019-11-30 06:53:18
问题 I am about to write a PowerShell Script for Windows administrators, in order to help them in certain tasks related to deployment of a web application. Is there any reason I should favor or exclude the development of a PowerShell Module (.psm1) instead of doing a PowerShell script (.ps1) ? Arguments to develop a Script simplicity : I think that using a script is a bit easier and more straightforward for Windows Administrators as it does not require the module to be installed (but I might be

How to stop a vb script running in windows

房东的猫 提交于 2019-11-29 09:30:49
问题 I'm using windows 7 I wrote a script to check whether My Laptop is running in Battery or AC current. I googled it and succedded in that. dim a a=1 Do While a=1 If IsLaptop( "." ) Then ' WScript.Echo "Laptop" Else ' WScript.Echo "Desktop or server" End If Loop Function IsLaptop( myComputer ) On Error Resume Next Set objWMIService = GetObject( "winmgmts://" & myComputer & "/root/cimv2" ) Set colItems = objWMIService.ExecQuery( "Select * from Win32_Battery", , 48 ) IsLaptop = False For Each

Is it secure to use a password argument in a Windows command?

ⅰ亾dé卋堺 提交于 2019-11-29 08:45:40
Imagine that we have a program or script that can take a password (or other sensitive information) argument: > program.exe /password:secret For Linux, best practice generally recommends against specifying the password directly on the command-line because of potential security concerns (the password can appear in the shell's history file and the system's process table): $ ./program.sh --password 'secret' & [1] 4152 $ cat /proc/4152/cmdline /bin/sh./program.sh--passwordsecret However, when searching around, I don't see the same vigorous recommendation for Windows. When writing programs and

When to choose development of a PowerShell Module over PowerShell Script

白昼怎懂夜的黑 提交于 2019-11-28 22:55:36
I am about to write a PowerShell Script for Windows administrators, in order to help them in certain tasks related to deployment of a web application. Is there any reason I should favor or exclude the development of a PowerShell Module (.psm1) instead of doing a PowerShell script (.ps1) ? Arguments to develop a Script simplicity : I think that using a script is a bit easier and more straightforward for Windows Administrators as it does not require the module to be installed (but I might be wrong as I am not a Windows Admin!). faster development : developing a module requires more careful

How to capture the Return Value of a ScriptBlock invoked with Powershell's Invoke-Command

浪尽此生 提交于 2019-11-28 18:39:00
My question is very similar to this one , except I'm trying to capture the return code of a ScriptBlock using Invoke-Command (so I can't use the -FilePath option). Here's my code: Invoke-Command -computername $server {\\fileserver\script.cmd $args} -ArgumentList $args exit $LASTEXITCODE The problem is that Invoke-Command doesn't capture the return code of script.cmd, so I have no way of knowing if it failed or not. I need to be able to know if script.cmd failed. I tried using a New-PSSession as well (which lets me see script.cmd's return code on the remote server) but I can't find any way to

How do I execute cmd commands through a batch file?

99封情书 提交于 2019-11-27 17:29:12
I want to write a batch file that will do following things in given order: Open cmd Run cmd command cd c:\Program files\IIS Express Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0 Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx Note: The cmd window should not be closed after executing the commands. I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express" , but it is not solving my purpose. So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it. Try

Batch Script Issue - How do I convert the dates or suggest any logic to satisfy the IF statement requirements in the given code?

半腔热情 提交于 2019-11-27 16:29:08
I have this already initialized batch script codes running in bat file: @echo off setlocal EnableExtensions DisableDelayedExpansion rem // Define constants here: set "_ROOT=%~dp0." & rem // (common root directory; `%~dp0.` is script's parent, `.` is current) set "_DIR1=%_ROOT%\Directory1" & rem // (1st directory containing files) set "_DIR2=%_ROOT%\Directory2" & rem // (2nd directory containing files) set _MASKS="*INV*." "*SLS*." & rem // (list of quoted file masks) set "_TMP1=%TEMP%\%~n0_1_%RANDOM%.tmp" & rem // (1st temporary file) set "_TMP2=%TEMP%\%~n0_2_%RANDOM%.tmp" & rem // (2nd