Windows login script to add line in configuration file - windows

I am new to this website, and fairly inexperienced with scripting, so be easy on me.
For this particular issue, my environment consists of roughly 1,000 Windows 7 PCs. Every PC has a Solarwinds Log and Event Manager agent running in the background that writes to a LEM server for each PC. Each PC has a configuration file titled spop.conf located in C:\Windows\SysWOW64\ContegoSPOP (I am assuming all PCs are 64 bit). I need to add the line "UseLocalEnvironmentVariableForLocalHost=true" to that file on all PCs in the environment. To do this, I also need to stop the service "Contego_Spop" and restart it after editing. Would it be best to create a new spop.conf file with this line in it and push that out via script?
Does anyone have some words of wisdom for a newbie? Thank you for any help you can give.

I assume you're a domain admin.
Write a .bat file fix.bat that accepts computer name, edits the config file and restarts the service.
sc \\%1 stop Contego_Spop
echo UseLocalEnvironmentVariableForLocalHost=true >>\\%1\c$\Windows\SysWOW64\ContegoSPOP\spop.conf
sc \\%1 start Contego_Spop
run this bat file for each computer name
C:\> call fix.bat host1
C:\> call fix.bat host2
C:\> call fix.bat host3
...

Related

Using wmic to start a process on a remote machine as part of a .bat file

TL;DR - I simply want a way to start a powerpoint presentation on a remote machine via command line / batch file using wmic (not PSEXEC).
A litte info...
I am trying to run a process on a remote machine on our network (POWERPNT.EXE). The purpose of this is that we have a .pptx presentation running on a TV in an entrance and this needs updating with info every day. Traditionally this has been done with VNC and simply editing the file but I want to improve this as the screen is part of a multi monitor set up and this can cause issues eslewhere.
So, my batch file will :
Kill the process on the remote machine running the .pptx
Open the file stored on the remote machine's desktop locally in Powerpoint
After saving the presentation in step 2, run the pptx. slide in auto show mode on the remote machine.
I have 1 and 2 working but am struggling to get the final part to run POWERPNT.EXE on the remote.
Here is my code:
wmic /node:"REMOTE-MACHINE-NAME" process call create "C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE /s \\REMOTE-MACHINE-NAME\SHARED-FOLDER\Presentation.pptx"
I don't want to use PSEXEC as not all operators that need to change this slide will have access to that on their PC's.

Running a bat file in background in windows

I need to run a bat file in background in windows.
I have tried using theSTART command.
The problem is, I connect to this machine remotely & if I log off, then the process gets killed.
Is there any way to keep a bat file running even after I log off from the remote machine?
Thanks in advance
Srvany: http://support.microsoft.com/kb/137890
RunAsService: http://runasservice.sourceforge.net/
Nssm: http://nssm.cc/
If you execute the bat file from a Windows service (using a service account) you will be able to log off and have the bat file execute in the background.
This walkthrough might be handy
http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx

auto run a bat script in windows 7 at login

I have recently acquired a windows 7 laptop from my late grandmother.
I have been using it for work and other things. I decided to create a VM using VirtualBox And now I want to create a user on the (Windows 7 Host) machine so that when I log into that user it autoruns a .bat script to start the VM. To make it clear I only want to run it only if the user "VM" logs in and not my normal user and it would be super awesome if it would autostart in full screen. I have a shortcut on my desktop that executes the command:
"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "VM" --startvm "12dada4d- 9cfd-4aa7-8353-20b4e455b3fa"
but how do I make an autorun.bat when I log into the User "VM"?
To run the batch file when the VM user logs in:
Drag the shortcut--the one that's currently on your desktop--(or the batch file itself) to Start - All Programs - Startup. Now when you login as that user, it will launch the batch file.
Another way to do the same thing is to save the shortcut or the batch file in %AppData%\Microsoft\Windows\Start Menu\Programs\Startup\.
As far as getting it to run full screen, it depends a bit what you mean. You can have it launch maximized by editing your batch file like this:
start "" /max "C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "VM" --startvm "12dada4d-9cfd-4aa7-8353-20b4e455b3fa"
But if VirtualBox has a truly full-screen mode (where it hides even the taskbar), you'll have to look for a command-line parameter on VirtualBox.exe. I'm not familiar with that product.
I hit this question looking for how to run batch scripts during user logon on a standalone windows server (workgroup not in domain). I found the answer in using group policy.
gpedit.msc
user configuration->administrative templates->system->logon->run these programs at user logon
add batch scripts.
you can add them using cmd /k mybatchfile.cmd if you want the command window to stay (on desktop) after batch script have finished.
gpupdate - to update the group policy.
Just enable parsing of the autoexec.bat in the registry, using these instructions.
:: works only on windows vista and earlier
Run REGEDT32.EXE.
Modify the following value within HKEY_CURRENT_USER:
Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ParseAutoexec
1 = autoexec.bat is parsed
0 = autoexec.bat is not parsed

Net use works in batch file, fails in script

We are a small office with a Linux appliance server (SAMBA) and Win7HP on the desktops. We have one machine that acts as a "backup server" and backs up the server nightly.
Writing what was supposed to be a quick & dirty addition to the backup script that would loop like this:
a. net use * /d /y
b. net use u: \\ourserver\userNN /u:userNN password
c. run sync util to sync u: to this user's storage space on backup server
d. repeat
If I manually create the above in a batch file, everything works fine. (However, for many reasons the procedure must be automated and tied into our existing backup scripts.)
If a script creates the identical batch file and runs it, the first user is logged-in and syncronized, but all subsequent net use attempts fail.
Similarly, if the script attempts to map the drive through code, this message is received:
Unrecognised network error #183
The above error suggests that the network drive/path is unavailable -- but a net use command typed at the command line using identical parameters is successful.
The "backup server" is a Win7HP box with UAC disabled. When cmd prompt is launched, all windows are preceded by the word: Administrator: -- however, when the script launches a command window to net use the drive, the cmd titlebar lacks that prefix.
Any thoughts / ideas?
In order for users to execute this code properly, they will need to have the proper credentials to do so. Also to automate this task, just use Task Scheduler and it should work fine.

How to copy the file from one windows machine to another windows machine in a particular drive using batch script?

In my windows server, am taking SQL DB backup in C drive. I wants to copy this .bak file to some other client windows machine in a particular drive with the current date using batch script. So that i can schedule this batch script using scheduled task. please help me out.
Can anyone, give a script to run this. thanks
Batch files are always tricky to get just right. First I'd open a command line and see if you can copy between two machines using the following syntax:
copy C:\localfile.bak \\remotemachine\c$\Path\remotefile.bak
(where "remotemachine" is the name of the remote machine and "c$" is the drive you wish to copy to). You can then copy this into a batch file and set up a scheduled task.
As for renaming the file to have the current date and time, I suggest you start with this question as it may involve some effort to get it into a format you want.

Resources