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.
VB ScriptWindows 7

Avatar of undefined
Last Comment
modono99

8/22/2022 - Mon
Krzysztof Pytko

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

Regards,
Krzysztof
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
Krzysztof Pytko

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
modono99

ASKER
ok thanks will distribute points as both answers explain that there is no simple solution to this.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck