Link to home
Start Free TrialLog in
Avatar of modono99
modono99

asked on

cscript vbscript.vbs not run in elevated mode Permissions

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.
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

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

Regards,
Krzysztof
Avatar of modono99
modono99

ASKER

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
SOLUTION
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok thanks will distribute points as both answers explain that there is no simple solution to this.