Page 1 of 1 1
Topic Options
#65902 - 2002-05-31 02:39 AM Access Denied stopping remote service
jtrainer Offline
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 [Cool]

*****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
#65903 - 2002-05-31 02:54 AM Re: Access Denied stopping remote service
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
2 questions

1. When you say local admin rights, do you mean to these member servers? or Domain Controllers?

2. If they are Admins on the Server, then they don't need any elevated permissions do they? As an Admin they can do anything they want. Unless you mean stuff like advanced rights to act as part of system, etc...

Please clarify and also let us know the version of KiXtart you're using.

If the user can do it from a DOS prompt, they should be able to do it from KiXtart. Just need to set the code right.

... By the way, what is up with all those EXECUTES kind of overKILL isn't it?

[ 31 May 2002, 02:58: Message edited by: NTDOC ]

Top
#65904 - 2002-05-31 03:03 AM Re: Access Denied stopping remote service
jtrainer Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 36
Thanks for the fast response.

1: Sorry, my mistake, we made them Server Operators. Tested their ability to stop / start with Server Manager.

2: I'm using 4.02 Kix.

The server is an NT4 BDC, (second test server is non DC) The user is running W2K.

I should point out there is 2 domains with a full two way transitive trust. (yes m$ training).

What throws me off, is Server manager works. I have gone to the private news groups in MS, and have verified that both server manager and netsvc use the same RPC call, to perform the operation.

jt
_________________________
Bumped my mouse again, time to reboot Windoze....
Top
#65905 - 2002-05-31 03:07 AM Re: Access Denied stopping remote service
jtrainer Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 36
NTDOC,

they cannot do this from the command prompt either.

The executes are just to make it pretty. The users are women, and my boss prefers more user readable prompts through out. I like the execute vs. just tossing a comment out. My way would be more like starting, done, and in the rare case, error.
_________________________
Bumped my mouse again, time to reboot Windoze....
Top
#65906 - 2002-05-31 03:10 AM Re: Access Denied stopping remote service
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
What I meant when I said, from the DOS prompt, was not to have them do it there. But to verify that it can be done outside of KiXtart.

Here is a nice UDF from Howard that should be able to do it.

fADSIServiceRun() - ADSI routine that starts, stops ,pause, and continues a service

Top
#65907 - 2002-05-31 05:51 AM Re: Access Denied stopping remote service
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#65908 - 2002-05-31 08:27 PM Re: Access Denied stopping remote service
jtrainer Offline
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
#65909 - 2002-05-31 09:43 PM Re: Access Denied stopping remote service
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What is wrong with using
code:
? 'Print this text'

to print stuff to the screen?
_________________________
There are two types of vessels, submarines and targets.

Top
#65910 - 2002-05-31 09:45 PM Re: Access Denied stopping remote service
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It doesn't look nearly as impressive as Execute() [Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#65911 - 2002-05-31 09:51 PM Re: Access Denied stopping remote service
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
$rc=execute('shell "%COMSPEC% /c /e:1024 @ECHO Print this on the screen"')

might work too [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#65912 - 2002-05-31 11:27 PM Re: Access Denied stopping remote service
jtrainer Offline
Fresh Scripter

Registered: 2002-03-06
Posts: 36
All, thanks for the thoughts. I guess I 'Execute'd a can of worms here. [Wink]

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... [Big Grin]
_________________________
Bumped my mouse again, time to reboot Windoze....
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 885 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.06 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org