troubleshooting Question

cscript vbscript.vbs not run in elevated mode Permissions

Avatar of modono99
modono99 asked on
VB ScriptWindows 7
5 Comments2 Solutions1562 ViewsLast Modified:
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)
                              

Note this can also be reproduced by running cscript vbscript.vbs with parameters on a cmd shell that has been started in Administrator mode.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros