Content Type
Profiles
Forums
Events
Everything posted by Scr1ptW1zard
-
Batch file request
Scr1ptW1zard replied to engert100's topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
I am not sure if this works 100% of the time, but I have used this in the past: if %userdomain% EQU %computername% ( echo Not a member of a domain. ) else ( echo Member of %userdomain% ) I have noticed that when a system is not a member of a domain, both the userdomain and computername environment variables are the same. Only tested under XP. -
Create your own MMC: Launch MMC. Add the Services snap-in. Customize it the way you want. Save to the file name you like. Launch this "new" services console view instead of the default services.msc and your customizations will be set.
-
net use /user:domain\username password?
Scr1ptW1zard replied to realized's topic in Windows 2000/2003/NT4
From the error message you provided, it sounds like you are already connected to the server under alternate credentials. Try disconnecting from the server prior to attempting to map a drive under the other credentials. The following batch file will disconnect all mapped drives, that are not in use, then perform the drive mapping under the given credentials. @echo off set "svrname=server" set "share=share$" set "usr=administrator" set "pwd=password" for /f "tokens=2" %%# in ('net use^|find /i "\\%svrname%"') do net use %%# /delete>nul net use l: \\%svrname%\%share% /user:%usr% "%pwd%">nul -
Use shared folder as local drive for an old application
Scr1ptW1zard replied to allen2's topic in Windows 2000/2003/NT4
What OS are you running? Have you tried 'mountvol'? mountvol D:\ X:\share -
Wow! Thank you for the compliment Yzöwl! This was one of those challenges that I just could not stop working on. So many times I was getting close but missing one special character. I ended up scraping everything and starting from scratch today with a completely different thought process. Methodically stepping through what needed to be done, made me see a straight-forward solution. Thank you very much for your comments. I am glad to contribute to this fine community. <Edit> : Updated solution for changed parameters I think this should handle all the requirements: @echo off :: Existing Filename [to add text to] Set "EF=existing.txt" :: Line Number [to insert string] Set "LN=13" :: Text String [to add] Set "TS=Text string added!" :: New Filename [as updated document] Set "NF=NewFile.ext" if exist %NF% del %NF% call :_dec LN for /L %%# in (1,1,%LN%) do ( call :_doit %%# ) echo %TS%>>%NF% more +%LN% %EF%>>%NF% goto _end :_dec set /a %1 -=1 goto :eof :_doit findstr /N /R "." %EF%|findstr /B /C:"%1:">nul if errorlevel 1 ( echo.>>%NF% ) else ( for /f "tokens=1,* delims=: " %%a in ('findstr /N /R "." %EF%^|findstr /B /C:"%1:"') do ( if [%%b] EQU [] ( echo. >>%NF% ) else ( echo %%b>>%NF% ) ) ) goto :eof :_end A bit slower as the line number for the insertion is increased. I tested inserting the line at each line of the file as well as lines that do not exist. When entering a line greater than the number of lines in the file, additional lines are added to reach the desired line. </Edit>
-
Ok, after a few days of scratching my head and trying many elaborate combinations, I have come up with the following: @echo off set linecount=0 :: Existing Filename [to add text to] Set "EF=existing.txt" :: Line Number [to insert string] Set "LN=3" :: Text String [to add] Set "TS=Text string added!" :: New Filename [as updated document] Set "NF=NewFile.ext echo %TS%>insert.txt if exist top.txt del top.txt for /f "tokens=*" %%l in (%EF%) do ( call :inc linecount call :print %%l ) call :dec LN more +%LN% %EF%>last.txt copy /b top.txt+insert.txt+last.txt %NF%>nul goto end :print if %linecount% LSS %LN% echo %*>>top.txt goto :eof :dec set /a %1=%1-1 goto :eof :inc set /a %1=%1+1 goto :eof :end This is using no external utilities. Works under Windows XP. Thoughts? Tidied version: @Echo off&Setlocal :: Existing Filename [to add text to] Set "EF=existing.txt" :: Line Number [to insert string] Set "LN=3" :: Text String [to add] Set "TS=Text string added!" :: New Filename [as updated document] Set "NF=NewFile.ext ::Type Nul>%NF% Set LC=0 Echo/%TS%>_#$_2 For /f "delims=" %%# In (%EF%) Do (Set/a LC +=1&Call :PR_ %%#) Set/a LN -=1 More +%LN% %EF%>_#$_3 Copy/b _#$_1+_#$_2+_#$_3 %NF%>Nul&&Del _#$_* Goto :Eof :PR_ If %LC% Lss %LN% Echo/%*>>_#$_1
-
Based on the information provided, the following may get you started: @echo off set offset=30 set filename=test.txt set tempfile=temp.tmp set linecount=0 ::: Delete files if they exist if exist %filename% del %filename% if exist %tempfile% del %tempfile% :: Populate file with dummy data for testing for /l %%n in (1,1,35) do echo %%n>>%filename% :: Loop through file to find line offset setlocal enabledelayedexpansion for /f %%# in (%filename%) do ( set /a linecount=!linecount!+1 if !linecount! EQU %offset% ( echo %%# Offset reached!>>%tempfile% ) else ( echo %%#>>%tempfile% ) ) endlocal The above simply allows you to change a line given the line number specified by the offset variable. A new file is created with the changes made. Additional changes could be made to check for a specific string at the offset line. Also, there is currently no error checking. If a file does not contain a given line offset, what should be done? Hope that helps!
-
Batch DIR output formatting
Scr1ptW1zard replied to twig123's topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
If you only want the files, use dir /b /on /a-d [d:\path]. Like this: @echo off setlocal enabledelayedexpansion for /f "tokens=*" %%# in ('dir /b /on /a-d c:\') do set _lst_=!_lst_!%%#^^^| echo !_lst_! endlocal -
VBscript help
Scr1ptW1zard replied to `Felix`'s topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
To have the service start mode pre-selected with the current setting, change your GetServices subroutine to retrieve the current mode and "check" the appropriate radio button like so: Sub GetServices strheader = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='header'>" & _ objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>" strNAME = "<table border='0' style='border-collapse: collapse' " & _ "bordercolor='#111111' width='100%'>" Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service") For Each objItem In colItems intNumber = intNumber +1 strNAME = strNAME & "<tr>" strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _ "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _ "</td></tr><tr><td id='options'>" &_ "<input type='radio' name='" + objItem.Name + "' value='Disable' OnClick='getOption(this)'" if lcase(objItem.StartMode)="disabled" then strName=strName + " checked" strName=strName & ">Disable" &_ "<input type='radio' name='" + objItem.Name + "' value='Automatic' OnClick='getOption(this)'" if lcase(objItem.StartMode)="auto" then strName=strName + " checked" strName=strName & ">Automatic" & _ "<input type='radio' name='" + objItem.Name + "' value='Manual' OnClick='getOption(this)'" if lcase(objItem.StartMode)="manual" then strName=strName + "checked" strName=strName & ">Manual</td></tr>" & _ "<tr><td> </td></tr>" NumTotalServices = intNumber Next header.InnerHTML = strheader strName = strName & "</table>" content.InnerHTML = strNAME 'MsgBox NumTotalServices End Sub As for recording any changes, you actually already have this functionality. Simply write your changes from the GetOption subroutine: Sub getOption(optobj) oList.WriteLine "Change made: " + optobj.name + ": " + optobj.value End Sub That should do it. -
VBscript help
Scr1ptW1zard replied to `Felix`'s topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
You could change a couple of things... Remove the onclick routine from each radio button. Add another button to perform the change. Here is your code with the changes. I only commented out the getOption line that was writing the file, you can remove this subroutine and the associated calls to it if you like. <head> <title>ModifyServices Configurator</title> <hta:application ID="objHTA" VERSION="1.0" icon="simple.ico" applicationName="ModifyServices Configurator" border=dialog borderStyle=normal caption=yes contextMenu=yes innerBorder=yes maximizeButton=yes minimizeButton=yes navigable=yes scroll=yes selection=yes showInTaskBar=yes sysMenu=yes singleInstance=yes windowState=normal /> <style> html, form, body, span { margin:0; font-family:Arial, Helvetica, sans-serif; border:0px; background-color: ghostwhite; } #content, #DiscriptionArea, #dName, #Options, td { font-size:12px; padding:5px; } #header { text-align:center; color: #FFFFFF; background-color: #3366FF; font-size:18px; font-weight: bold; border:0px; } #content{ position:absolute; left:0px; width:100%; height:440px; /*overflow:auto;*/ } #dName, #dDisc { background-color: #EAEAFF; font-weight: bold; border-top:solid 1px black; } #dDisc { border-top:solid 1px black; font-weight: normal; font-style: italic; } #options { background-color: #FFFFCC; } * html, * html body { overflow-y: hidden!important; height: 100%; margin: 0; padding: 0; } * html #content { height: 440px; overflow-y: scroll; position: relative; } * html #header, * html #header-bottom, * html #header-middle position: absolute; * html #footer, * html #footer-bottom, * html #footer-middle { position: absolute; bottom:0px; } </style> <script language="javascript"> function Save() { var all=document.body.all.tags("INPUT"); for(var i=0;i<all.length;i++) { if(all[i].type=="radio" && all[i].checked) { oList.writeline(all[i].name + ": " + all[i].value); } } } </script> <script language="vbscript"> Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim strComputer : strComputer = "." Dim ObjWMI, oList, objItem, colItems, SysName, Lst Set ObjWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") '/-----------------------------------------------------------------------> Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", WmiVar) '/-----------------------------------------------------------------------> For Each objItem In colItems SysName = objItem.CSName Next Lst = ".\List of Current Services on " & SysName & ".lst" Set oList = Fso.OpenTextFile(Lst, 2, True) Sub GetServices strheader = "<table width='100%' height='40px'><tr><td align='center' valign='middle' id='header'>" & _ objHTA.applicationName & " "& objHTA.Version & "</td></tr></table>" strNAME = "<table border='0' style='border-collapse: collapse' " & _ "bordercolor='#111111' width='100%'>" Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service") For Each objItem In colItems intNumber = intNumber +1 strNAME = strNAME & "<tr>" strNAME = strNAME & "<td id='dName' nowrap>" & objItem.DisplayName & _ "</td><td rowspan='2' id='dDisc'>" & objItem.Description & _ "</td></tr><tr><td id='options'>" &_ "<input type='radio' name='" + objItem.Name + "' value='Disable' OnClick='getOption(this)'>Disable" &_ "<input type='radio' name='" + objItem.Name + "' value='Automatic' OnClick='getOption(this)'>Automatic" & _ "<input type='radio' name='" + objItem.Name + "' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _ "<tr><td> </td></tr>" NumTotalServices = intNumber Next header.InnerHTML = strheader strName = strName & "</table>" content.InnerHTML = strNAME 'MsgBox NumTotalServices End Sub Sub getOption(optobj) ' oList.WriteLine optobj.name + ": " + optobj.value End Sub Sub GetDisc Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service") For Each objItem In colItems strDISC = strDISC & objItem.Description & "<br><br>" Next DiscriptionArea.InnerHTML = strDISC End Sub Sub ClearDisc Set colItems = ObjWMI.ExecQuery("SELECT * FROM Win32_Service") For Each objItem In colItems strDISC = strDISC Next DiscriptionArea.InnerHTML = strDISC End Sub '/-----------------------------------------------------------------------> Sub Window_Onload Set colItems = objWMI.ExecQuery("Select * From Win32_DesktopMonitor") For Each objItem In colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 800) / 2 intTop = (intVertical - 600) / 2 window.resizeTo 800,600 window.moveTo intLeft, intTop GetServices window.focus() 'playSound End Sub Sub playSound strSoundFile = ".\whats_going_on.wav" Set objShell = CreateObject("Wscript.Shell") strCommand = "sndrec32 /play /close " & Chr(34) & strSoundFile & Chr(34) objShell.Run strCommand, 0, True End Sub </script> </head> <body> <form name="form1"> <span id="header"></span> <span id="text"><p>Selection what option you would like for each service.</p> <table width="50%" border="0" align="center" cellpadding="5"> <tr> <th width="33%" align="right"><input type="button" value="Create Configuration Files" onclick="Radios()"></th> <th width="33%" align="middle"><input type="reset" value="Reset/Clear All Values" ></th> <th width="33%" align="left"><input type="button" value="Save All Values" onclick="Save()"></th> </tr> </table> </span> <span id="content"></span> <span id"footer"></span> </form> </body> -
VBscript help
Scr1ptW1zard replied to `Felix`'s topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
A couple of things that I see would be the following: Make sure that the following is inserted before the script tag for "vbscript". <script language="javascript"> </script> All your option buttons are being given the same name. Change the following: "<input type='radio' name='object1' value='Disable' OnClick='getOption(this)'>Disable" &_ "<input type='radio' name='object1' value='Automatic' OnClick='getOption(this)'>Automatic" & _ "<input type='radio' name='object1' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _ to "<input type='radio' name='object" + cstr(intNumber) + "' value='Disable' OnClick='getOption(this)'>Disable" &_ "<input type='radio' name='object" + cstr(intNumber) + "' value='Automatic' OnClick='getOption(this)'>Automatic" & _ "<input type='radio' name='object" + cstr(intNumber) + "' value='Manual' OnClick='getOption(this)'>Manual</td></tr>" & _ That seems to work for me under XP SP3. -
VBscript help
Scr1ptW1zard replied to `Felix`'s topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
Give this a try: <html> <head> <title>Test</title> <HTA:APPLICATION ID = "objApp" APPLICATIONNAME = "Test" /HTA:APPLICATION> </head> <script language=javascript> </script> <script language=vbscript> sub getOption(optobj) msgbox optobj.name + ": " + optobj.value end sub </script> <body> <table border="1" width="300"> <tr> <td>object 1</td> </tr> <tr> <td> <input type="radio" value="Disable" name="Rad1" OnClick='getOption(this);'> Disable <input type="radio" value="Automatic" name="Rad1" OnClick='getOption(this);'> Automatic <input type="radio" value="Manual" name="Rad1" OnClick='getOption(this);'> Manual </td> </tr> <tr> <td>object 2</td> </tr> <tr> <td> <input type="radio" value="Disable" name="Rad2" OnClick='getOption(this);'> Disable <input type="radio" value="Automatic" name="Rad2" OnClick='getOption(this);'> Automatic <input type="radio" value="Manual" name="Rad2" OnClick='getOption(this);'> Manual </td> </tr> <tr> </table> </body> </html> -
Password Never Expires - Changing automatically
Scr1ptW1zard replied to dslider's topic in Windows XP
OK, I am not able to reproduce this error . I provided you with pwexpire2.vbs for you to run directly instead of creating it within the batch file. Your result was: My result: desired user account(s) set to must change password. I provided you with AllUserPWExpire.vbs to see if the script would set all user accounts to must change password. Your result was: My result: All user accounts set to must change password. I hope someone else can reproduce the error and shed some light on a solution. The attached file contains the two scripts mentioned. PWExpire.zip -
Password Never Expires - Changing automatically
Scr1ptW1zard replied to dslider's topic in Windows XP
Oops! Sorry about that. Here is a correction: @echo off if not [%1]==[] ( echo Const ADS_UF_EXPIRE_PASSWD = ^&H01111 >.\pwexpire.vbs echo Dim User >>.\pwexpire.vbs echo Dim usrflags >>.\pwexpire.vbs echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs echo User.Put "userFlags", usrflags AND ADS_UF_EXPIRE_PASSWD >>.\pwexpire.vbs echo User.SetInfo >>.\pwexpire.vbs echo Set User = Nothing >>.\pwexpire.vbs cscript //nologo .\pwexpire.vbs if exist .\pwexpire.vbs del .\pwexpire.vbs ) -
Password Never Expires - Changing automatically
Scr1ptW1zard replied to dslider's topic in Windows XP
Here is a batch file that uses a vbscript to perform the task: Save this as pwexpire.cmd @echo off if not [%1]==[] ( echo Const ADS_UF_DONT_EXPIRE_PASSWD = ^&H10000 >.\pwexpire.vbs echo Dim User >>.\pwexpire.vbs echo Dim usrflags >>.\pwexpire.vbs echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs echo User.Put "userFlags", usrflags Or ADS_UF_DONT_EXPIRE_PASSWD >>.\pwexpire.vbs echo User.SetInfo >>.\pwexpire.vbs echo Set User = Nothing >>.\pwexpire.vbs cscript //nologo .\pwexpire.vbs if exist .\pwexpire.vbs del .\pwexpire.vbs ) Call this batch file like this: pwexpire.cmd userid -
RESOLVED -- adding a carriage return in a bat script
Scr1ptW1zard replied to dslider's topic in Windows XP
Try this: net user TestUser IhateThisStuff0! /add /y -
Bat file help
Scr1ptW1zard replied to Smiley357's topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
Here is an explanation to my script: 'fsutil fsinfo drives^|more' The output from the above command produces this output (your drive list may vary): Drives: A:\ C:\ D:\ E:\ X:\ But we only want the drive letters, so I remove the string "Drives:" with set chkdrive=!chkdrive:Drives:=! The above simply replaces the string "Drives:" with "". The statement set chkdrive=!chkdrive: =! Does a similar replacement of the space " ". This is not really needed, but I like to be neat. The exclamation marks (!) are required when referencing environment variables (instead of %) while enabledelayedexpansion is set. Yzöwl's script works as well, and actually eliminates the need for what I am performing as described above. The problem you may be having with his script could be that your USB drive is not recognized as a "Removable Drive". I actually have two USB drives attached to my system, and one is seen as a "Removable Drive" while the other is seen as a "Fixed Drive". To test this, run the following command (replace D:\ with your USB drive): fsutil fsinfo drivetype D:\ For Yzöwl's script to work, the above command will need to return: D:\ - Removable Drive My script is checking all drives that are NOT a CD-ROM drive, therefore you are receiving the desired result. -
Bat file help
Scr1ptW1zard replied to Smiley357's topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
Perhaps this will work for you. I am assuming that you have the fsutil command available. This will skip checking against CD-ROM drives. @echo off for /f "tokens=*" %%a in ('fsutil fsinfo drives^|more') do ( setlocal enabledelayedexpansion set chkdrive=%%a set chkdrive=!chkdrive:Drives:=! set chkdrive=!chkdrive: =! fsutil fsinfo drivetype !chkdrive!|find /i "CD-ROM">nul if errorlevel 1 call :doStuff !chkdrive!) goto skipme :doStuff endlocal if exist %1Install set drive=%1 goto :eof :skipme endlocal echo Performing task on %drive% You may need to change the statement in the doStuff routine to check for your folder/file. -
You should look at the Filever.exe tool: http://support.microsoft.com/kb/913111
-
VBS substring
Scr1ptW1zard replied to iceangel89's topic in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
You may want to look at using the FileSystem Object for your purpose here. You can see an example here: http://www.devguru.com/technologies/vbscri...etbasename.html -
I created the script below to perform a similar partitioning configuration. This is just a snippit of the script I use that shows how to perform the calculation using native batch commands. This should give you a good starting point. @echo off setlocal enabledelayedexpansion echo list disk>%temp%\listdisk.dp diskpart /s %temp%\listdisk.dp >%temp%\disklist.dat if exist %temp%\mkdisks.dp del %temp%\mkdisks.dp>nul for /f "tokens=1-4 delims= " %%a in ('find /v "###"^<%temp%\disklist.dat^|find " Disk "') do ( set size=%%d if !size! LSS 1024 set /a size=!size!*1024 set cdrv=18432 for /l %%s in (18432,-4096,4096) do if !cdrv! gtr !size! set cdrv=%%s echo select %%a %%b >>%temp%\mkdisks.dp echo create partition primary size=!cdrv! NOERR >>%temp%\mkdisks.dp echo assign letter c NOERR >>%temp%\mkdisks.dp echo active >>%temp%\mkdisks.dp set /a size=!size!-!cdrv! set /a ddrv=!size!/10 set /a ddrv=!ddrv!*8) if !ddrv! GTR 0 ( echo select %%a %%b >>%temp%\mkdisks.dp echo create partition primary size=!ddrv! NOERR >>%temp%\mkdisks.dp echo assign letter d NOERR >>%temp%\mkdisks.dp set /a edrv=!size!-!ddrv! if !edrv! GTR 0 ( echo select %%a %%b >>%temp%\mkdisks.dp echo create partition primary NOERR >>%temp%\mkdisks.dp echo assign letter e NOERR >>%temp%\mkdisks.dp) ) else ( echo select %%a %%b >>%temp%\mkdisks.dp echo create partition primary NOERR >>%temp%\mkdisks.dp echo assign letter d NOERR >>%temp%\mkdisks.dp)) endlocal diskpart /s %temp%\mkdisks.dp This code creates a diskpart script, called mkdisks.dp. First, a "C:" partition with a max of 18GB to a min of 4GB in 4GB increments, depending on the amount of hard disk space, is added to the diskpart script. The remaining space is split to 80% for the "D:" partition, and the remaining to the "E:" partition.
-
For Syntax is driving me crazy ...
Scr1ptW1zard replied to midiboy's topic in Unattended Windows 2000/XP/2003
Try the following. FOR /f "usebackq tokens=2" %%i IN (`net use * %SHARE% %PASSWORD% /user:%USERNAME% /PERSISTENT:NO^|find /i "%SHARE%"`) DO @echo %%i