Solved

Access denied

Posted on 2014-01-21
8
359 Views
Last Modified: 2014-01-27
Support,

I want to stop/start the windows services using below command.

sc \\<serviceName> start <Service_Name>

But I'm getting access denied error. Is there anyway I can hardcode userid and password of the system before executing stop service command?
0
Comment
Question by:iamsateesh
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:tsaico
ID: 39797341
Is this for a remote computer or the computer you are on?

You can use the net start and stop commands

net stop <servicename>

Oh, and I also think you need the command line to run in an admin window, be it a batch or manually run.
0
 
LVL 17

Expert Comment

by:Chris Millard
ID: 39797361
You could also use PsExec (part of PsTools - http://technet.microsoft.com/en-gb/sysinternals/bb896649.aspx) to run the command.

With PsExec you can run a command on a local or remote machine, and you can also specify a username and password to run the command as.

Example (to run on a local PC)

psexec -u <domain\username> -p <password> sc \\<serviceName> start <Service_Name>
0
 

Author Comment

by:iamsateesh
ID: 39797753
I want to stop and start the services on remote computer from local laptop...
0
 
LVL 13

Expert Comment

by:frankhelk
ID: 39797985
I want to stop and start the services on remote computer from local laptop...

The PsExec (mentioned above) would be the method of choice.

Maybe you need to run it within a command shell, with i.e.
psexec -u <domain\username> -p <password> cmd /c net start <serviceName>

Open in new window

0
Promote certifications in your email signature

Has your company recently won an award or achieved a certification? They'll no doubt want to show it off. Email signature images used to promote certifications & awards can instantly establish credibility with a recipient and provide you with numerous benefits.

 

Author Comment

by:iamsateesh
ID: 39798269
Is there any batch script or vb script[script contains computer name, userid and password]
 I execute before stopping and starting the services?
0
 
LVL 13

Expert Comment

by:frankhelk
ID: 39799408
None I know of.

the commands
net start <serviceName>
net stop <serviceName>

Open in new window

will do anything needed to start/stop the service. NET is a transient command (executable file bundled into Windows).

PsExec is a tool for executing commands on a remote machine and part of the "Sysinternals Suite", a free collection of tools that once was independent. The suite got too good to remain independent, so MS hired the programmer and now the Sysinternals suite is part of Microsoft's tools collection (TechNet). It's old web address http://www.sysinternals.com now redirects to a Microsoft Technet site, where the tools could easily be found. They're worth a look in any case, by the way, an they're actively maintained.
0
 
LVL 9

Expert Comment

by:tsaico
ID: 39800147
Oh, are you on a domain?  If so, then the admin shares should also be enabled.  Otherwise, you will need to make at least one valid connection before you will be allowed to connect to the remote computer

here is a post on what I am talking about, just check out the guy's command line example, where he logs in as a local user once just to authenticate. then from there his sc command works fine
http://www.neowin.net/forum/topic/954040-how-do-you-startstop-windows-7-service-remotely/
0
 
LVL 13

Accepted Solution

by:
frankhelk earned 250 total points
ID: 39800222
Hmmm ... looks like that's needed for sc.

Since PsExec accepts credentials by its own, I presume that the PsExec attempt works well w/o logging in first (but I admit that I havn't tested that - just try yourself).

In both cases I presume that is not a problem if the user of the local machine is known on the target machine with the same credentials ... regardless of workgroup, domain or AD (easier when both are in the same domain or AD ...).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now