windows-scripting

Determining OS version via Scripting

你。 提交于 2019-12-11 21:09:03
问题 I found this script on another site but I can not get it to work and I don't know batch scripting that well Set objWshShell = WScript.CreateObject("WScript.Shell") strOSVersion = objWshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion") If strOSVersion = "5.1" Then Debug.WriteLine("Windows XP") Rem Insert Windows XP Statements ElseIf strOSVersion = "6.0" Then Debug.WriteLine("Windows Vista") Rem Insert Windows Vista Statements ElseIf strOSVersion = "6.1" Then

Batch Scripting:search file, extract numbers, and copy into new file

浪尽此生 提交于 2019-12-11 10:50:57
问题 I'm new to batch scripting and have a question. I was wondering if it's possible to search a .txt file by requirements and take data specified and copy into a new .txt file? Like if I have 50 lines with 9 digit numbers and a bunch of other crap I don't need after them can I say, "For any line beginning with a 1,2,3,4,5,6,7,8,or 9...take the first 9 digits and copy them into a new file, for all lines in the file???" I thought this would be easier than trying to delete all the other stuff. Let

Batch - How to echo exclamation mark inside string passed as parameter to subroutine?

有些话、适合烂在心里 提交于 2019-12-11 07:45:40
问题 I have the following script: @ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET /A countArgs=1 FOR %%p in (%pathListToCheck%) DO ( IF NOT EXIST %%p ( CALL :error "!countArgs!. Argument -> bla!" EXIT /B 1 ) SET /A countArgs+=1 ) :error ECHO ERROR set x=%~1 ECHO !x! EXIT /B 0 Unfortunately the exclamation mark does not get echo d. I also tried to escape it like ^! and ^^! but it doesn't work. I use delayed expension here to make the greater-then sign ( > ) work. If i would try to

Windows script - run silent but wait for completion / return right code

倖福魔咒の 提交于 2019-12-11 00:13:40
问题 Here's my situation: I have a BAT file that takes a long time to run (1minute to 70 minutes) I schedule it with Windows scheduler to run every 10 minutes If it schedules again while it is still running, nothing happens (this is good) My problem is that I need my BAT to run silently, and it doesn't. So, I want to launch it with a Windows script like the following: Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0 Set WshShell =

Using powershell and svn to delete unversioned files

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:57:15
问题 I'm trying to write a build script to checkout code using Powershell. I need to be able to replace any modifications which were made to the working copy with the appropriate changes from the SVN repo. That also includes deleting any files which were deleted in the repo but not deleted in the working copy. Unfortunately I cannot do a clean checkout, since it would be to inefficient to check out all 10GB of code every time the build script is run. How would I do this? I've been trying something

Querying a registry key in a batch script

大兔子大兔子 提交于 2019-12-10 17:49:39
问题 I'm using the following code to get a list of programs being run at start up, and log them to a file. for /f "skip=2 tokens=1,2*" %%A in ('REG QUERY "HKCU\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" 2^>NUL') do echo %%A : %%C >> Log.txt This works with entries where the value name doesn't contain a space, but when it does, such as with "Google Update", it messes up the tokens, and %%C becomes: REG_SZ <path> , instead of just the path. Does anyone have a better way to query the

How to suppress output and check whether or not a command is successful?

孤者浪人 提交于 2019-12-10 11:31:37
问题 I am trying to write a powershell script that tests if a MySQL login is successful by using $? to check if an error occurs. I also want to suppress all output - successful or not successful - from the command. These are the things I've tried: mysql -u root --password=mypass -e "show databases" If ( $? ) { echo "Hooray!" } Else { echo "Boo!" } This works correctly but doesn't suppress any output. mysql -u root --password=mypass -e "show databases" > $null Works correctly still but does not

Permanent removal of logo in Windows Scripting Host (WSH) scripts

空扰寡人 提交于 2019-12-10 07:53:08
问题 I know two ways to remove the logo permanently. The "official" one: cscript //Nologo //S Will save current command line options for current user. A ftype approach with admin privileges: ftype wsffile="%SystemRoot%\System32\CScript.exe" //nologo "%%1" %%* ftype jsfile="%SystemRoot%\System32\CScript.exe" //nologo "%%1" %%* ftype vbsfile="%SystemRoot%\System32\CScript.exe" //nologo "%%1" %%* Double- % 's are needed only if you use the lines in a batch file. The latter will all users via affect

Recursively append folder name to the files in Windows batch file

我是研究僧i 提交于 2019-12-08 10:44:41
问题 I would like to append my folder name to all the available .txt files inside a subfolder. Below is the file/directory structure. I need to achieve this in Windows BATCH script. C:\Source\Source1\1\a.txt C:\Source\Source1\1\b.txt C:\Source\Source1\2\a.txt C:\Source\Source1\2\b.txt C:\Source\Source2\3\a.txt C:\Source\Source2\3\b.txt The above files should be renamed like below: C:\Source\Source1\1\1_a.txt C:\Source\Source1\1\1_b.txt C:\Source\Source1\2\2_a.txt C:\Source\Source1\2\2_b.txt C:

Windows Batch SET Syntax

為{幸葍}努か 提交于 2019-12-08 09:23:32
问题 I have adopted some code from here: Extract substring between 2 strings Rem Looking for a test.txt substring preceded by page\[%%x\]= and succeeded by ; @Echo Off for /l %%x in (0, 1, 4) do ( echo %%x For /F "Delims=" %%A In ('FindStr /I "page\[%%x\]=.*;" "test.txt"') Do Call :Sub "%%A" "%%x" ) Pause GoTo :EOF :Sub Set "Line=%~1" Set "Up2Sub=%Line:*page[ %~2 ]=%" Set "SubStr=%Up2Sub:;="&:"%" Echo %SubStr% > test%~2.json Exit /B The issue I am having is regarding this line: Set "Up2Sub=%Line: