cscript vbscript.vbs not run in elevated mode Permissions

modono99
modono99 used Ask the Experts™
on
Hello,
I have a java executable program that has to run As Administrator. From this program I call cscript to execute a vbs script to open and attach files to an outlook message- this works fine if the executable is not run as administrator.  is there a way in vbs to set the environment back to USER before running this script . I have seen suggestions to use runas - but I don't want any interaction with user before displaying the outlook window.

the command run is cscript vbsscript.vbs <parameters>

Dim args, num 
On Error Resume Next 
 set args = WScript.Arguments 
num = args.Count
aTo = args.Item(0)
Subject = args.Item(1)
TextBody = args.Item(2)
Attach = args.Item(3)
'Create an Outlook object
Dim Outlook 'As New Outlook.Application
Set Outlook = WScript.CreateObject("Outlook.Application")
'Create e new message
Dim Message 'As Outlook.MailItem
Set Message = Outlook.CreateItem(olMailItem)
With Message
    .Display
    If Err.number <> 0 Then
        ' Reset error handling
        On Error Goto 0       
        WScript.Quit(-1) 
    End If
    .Subject = Subject
    .BodyFormat = 1
    .HTMLBody = TextBody
	 .Attachments.Add(Attach)
    'Set destination email address
    .Recipients.Add(aTo)
End With
WScript.Quit(0)
                              

Open in new window


Note this can also be reproduced by running cscript vbscript.vbs with parameters on a cmd shell that has been started in Administrator mode.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
Did you try to tick an option in Task Scheduler for this task Run with highest privileges ?

Regards,
Krzysztof

Author

Commented:
Hi Krzysztof,
I want the script  to run as USER - not with elevated permissions but because the calling program is run as Administrator it is picking this up
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012
Commented:
Hi,

So, you need to consider disabling UAC then try again but I'm not sure if it's possible to run this script without higher privileges.

Please wait for other experts, maybe someone fixed some similar issue in his/her environment :)

Krzysztof
Most Valuable Expert 2012
Top Expert 2014
Commented:
I don't know of a way to "back out" of an administrator token.  What you might be able to do is create a shortcut to the .JS file that has "Run with highest privileges set", then use a batch file to execute the JS, then the VBScript.  Since the VBScript will be run from the context of the batch file, my guess is that it should work.

Regards,

Rob.

Author

Commented:
ok thanks will distribute points as both answers explain that there is no simple solution to this.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial