#65902 - 2002-05-31 02:39 AM
Access Denied stopping remote service
|
jtrainer
Fresh Scripter
Registered: 2002-03-06
Posts: 36
|
All,
I have written 2 scripts that when executed, the first will stop 3 specific services on a remote server, the second will start the same services. Problem is, thye work, however users get access denied.
I start off asking for the user to type yes, and enter. The script then shells and executes netsvc.exe from the res kit. NetSvc.exe command line works for me as a Dom Admin. For these two users, they get access denied. No one would ask whats their access level? I have granted them both local admin rights, and even elevated their perms with ntrights.exe.
What does work; a batch script with a single line of SRVMGR.exe \\servername I have shown them how to stop the services, and how to start. Seems simple eh?
My reason for wanting my script to work, is I use the sendmail function I downloaded from here (Works Great) to let me know if a user has needed to stop / start the services in the middle of the night. I do not need to be paged unless there is some critical issue.
I ask this, does ones access permissions change in any way when Kix shells out?
I know there are some clean up items left in here from experiments, but if anyone has any critiques, I'm always happy to learn a new technique or way to do it
*****Here's the code ************************ ; **** Gentran Services Startup Script with Verification ****
Break Off Color w/b CLS Dim $sResponse, $sDirection, $sMachNam, $LogFile $sDirection = "Stop" ; Values accepted are Start and Stop $sMachNam = "EDIPROD" ; NetBios server Name of Server $msgSubject="ATTN: GENTRAN Services Changed Status" $msgBody="Gentran Services on $sMachNam have been $sDirection" + "ed." $msgRecip="MISNOTIFICATION@@MyDomain.com"
; Sets Window Title $ = SetTitle ("MyDomain Gentran Services for $sMachNam Script: $sDirection ")
$ = Execute ('"***************************************************************************"?') $ = Execute ('" @USERID, Are you sure you wish to $sDirection the Gentran Services?"?') $ = Execute ('" on $sMachNam!"?') $ = Execute ('" Please type Yes or No followed by Return. This is NOT case sensitive"?') $ = Execute ('"***************************************************************************"?') $ = Execute ('" Type Yes and press Enter to continue : "') Gets $sResponse
If $sResponse = "YES" ; Not Case sensitive YES = YeS =yes =yES $ = Execute ('"@USERID Replied $sResponse to $sDirection the services."?') $ = Execute ('"Please wait while we process your request..."?') $ = Execute ('"Now Starting the GENTRANExecutive service..."??') Shell "C:\WINNT\SYSTEM32\CMD /E:1024 /C " + "netsvc \\$sMachNam GENTRANExecutive /$sDirection" If @Error = 1 OR @ERROR = 0 Else If @ERROR = "3" $ = Execute ('"STOP: Notify the HelpDesk "?') $ = Execute ('"That you are missing netsvc.exe in your path. "?') $RC = LogEvent( 0 , 1 , "@USERID $sDirection" + "ed the Gentran Services" , "\\ironhorse" , "MYScripting") ; $RC = LogEvent( 0 , 1 , "@USERID $sDirection the Gentran Services" , \\$sMachNam "MYScripting") Return Else $ = Execute ('"Failed to Stop Service with FCode:@Error "?') $ = Execute ('"Which means @SERROR"?') Return EndIf EndIf $ = Execute ('"Now Starting the GENTRANServerCommunications service"?') Shell "C:\WINNT\SYSTEM32\CMD /E:1024 /C " + "netsvc \\$sMachNam GENTRANServerCommunications /$sDirection" If @Error = 1 OR @ERROR = 0 Else $ = Execute ('"Failed to Stop Service with FCode:@Error "?') $ = Execute ('"Which means @SERROR"?') EndIf $ = Execute ('"Now Starting the GENTRANServerMailbox service"?') Shell "C:\WINNT\SYSTEM32\CMD /E:1024 /C " + "netsvc \\$sMachNam GENTRANServerMailbox /$sDirection" If @Error = 1 OR @ERROR = 0 Else $ = Execute ('"Failed to Stop Service with FCode:@Error "?') $ = Execute ('"Which means @SERROR"?') EndIf sendmail($msgSubject, $msgBody, $msgRecip) ; $RC = LogEvent( 0 , 1 , "@USERID $sDirection" + "ed the Gentran Services" , \\$sMachNam , "MYScripting") Else ;User aborted, or failed to type yes correctly. $ = Execute ('"@USERID, Replied with $sResponse, which is equal to a NO!"?') ; sendmail($msgSubject, $msgBody, $msgRecip) ; Used to test failed yes prompt EndIf Exit 1
;;; ******************** DO NOT EDIT BELOW THIS LINE ****************** ;;; ******************** DO NOT EDIT BELOW THIS LINE ******************
Function sendmail($Subject, $Body, $Rec) ;Create Outlook Object $objOutlook=CreateObject("Outlook.Application") ;Create NewMessage Object $NewMessage=$objOutlook.CreateItem(0) ;Set Mail Subject $NewMessage.Subject=$Subject ;Set Mail Body $NewMessage.Body=$Body ;Add Recipients $Recip=$NewMessage.Recipients.add($rec) ;If Outlook cannot resolve the recipient, the message will be displayed If NOT $Recip.resolve $NewMessage.Display EndIf ;Send Message $NewMessage.send EndFunction Return
_________________________
Bumped my mouse again, time to reboot Windoze....
|
|
Top
|
|
|
|
#65907 - 2002-05-31 05:51 AM
Re: Access Denied stopping remote service
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
NTDOC is homing in on a good point. If you want to be able to start/stop services, see administrative shares, etc. You and/or your users executing these scripts have to be Domain Administrators. Otherwise, you will have to manually add them in.
- Kent
|
|
Top
|
|
|
|
#65908 - 2002-05-31 08:27 PM
Re: Access Denied stopping remote service
|
jtrainer
Fresh Scripter
Registered: 2002-03-06
Posts: 36
|
NTDOC,
In response, they cannot execute the netsvc.exe and stop / start the services, even at the prompt only. The weird thing is, srvmgr allows them, so per M$ I have the correct permissions for them. I will download the UDF and try it. I will be replacing the server soon, and it's replacement will not be a BDC.
Now aside from the real issue at hand, as well as my excessive use of the execute functions, is there any other critique in my methods used in this script?
I have used kix for many years, but usually just to manipulate a reg key, or some minor stuff. I only recently started to use it for more serious scripting. I always used the SMS installer to do most of this work, as I like the roll back functions it gives. So until now, I never worried about what was displayed to the screen.
thanks jt
_________________________
Bumped my mouse again, time to reboot Windoze....
|
|
Top
|
|
|
|
#65912 - 2002-05-31 11:27 PM
Re: Access Denied stopping remote service
|
jtrainer
Fresh Scripter
Registered: 2002-03-06
Posts: 36
|
All, thanks for the thoughts. I guess I 'Execute'd a can of worms here.
Still, even if the original error is not a Kix specific error, I'm going to try Howards UDF when the next failure of the services ocurs. Per M$, netsvc.exe should work if srvmgr is working (which it is). With all this brain power here, any ideas of what else may be happening? I know a user only needs server operator to stop / start services, so anyone see something like this in the past?
I'll keep the executes, as LLigetfa is right, it is more impressive to the untrained (my co-workers, who still havn't figured out what some of the other scripts are doing to their systems). I switched to the execute command after seeing a post and testing some code here, it just formated a screen print better at one time, and I just adopted it. As I have switched my variable standard.
dang it, bumped my mouse, time to reboot windows...
_________________________
Bumped my mouse again, time to reboot Windoze....
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|