I am currently trying to import a registry file in a logon script that uses VBScript. However a group of users have registry/cmd disabled through the group policy (unchangeable due to policy). The code works for users that have registry/cmd access just not for the rest.
Dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
wsh.Run "%SystemRoot%\regedit.exe /S \\LogonServer\LogonFiles\reg\languages.reg", , True
Related
I am calling a VBS function from an intranet page, using IE 11 (yes, it has to be that browser).
The function processes an Outlook mailbox, and is partly working: I can run down the list of mails and find the Subject and Body, but I need the sender's email address.
I can get this in various ways when I run similar code as an Outlook macro, but none of them work in VBS - the script just hangs (no error message) when I try to get anything of interest - see the function, with various things I've tried commented.
Any pointers as to where I'm going wrong gratefully received....
Function readEmails(mailbox)
Dim iCt
Set objOutlook = CreateObject("Outlook.Application")
Set NS = objOutlook.GetNamespace("MAPI")
Set olFolder = NS.Folders(mailbox)
Set olFolInbox = olFolder.Folders("Inbox")
iCt = 0
For iCt =1 to olFolInbox.Items.Count
set olMessage=olFolInbox.Items(iCt)
msgbox(ict & "-" & olMessage.Subject )
msgbox("SenderEmailType=" & olMessage.SenderEmailType)
msgbox("SenderEmailAddress=" & olMessage.SenderEmailAddress) 'hangs
'set sn=olMessage.SenderName 'hangs
set sUser=olMessage.Sender
'set sn=sUser.Name 'hangs
'msgbox(sUser) 'hangs
'set sExUser=sUser.GetExchangeUser ' hangs
End If
Next
readEmails=sReturn
End Function
It seems that a security issue takes its place when you automate Outlook from an external macro - it can be a security prompt or an exception in the code. How it is seen really depends on the Outlook version (its internal implementation). To avoid security issues when dealing with OOM you can use the following approaches:
Use a low-level API which doesn't trigger security issues in OOM. Outlook is built on top of Extended MAPI which doesn't trigger security issues unlike OOM. Also you may consider using any wrappers around this low-level API such as Redemption.
Use third-party components designed for turning off and on security checks in OOM, see Outlook Security Manager for more information.
You can create a group policy to prevent security prompts from displaying if any up-to-date antivirus software is installed on the system or just turn these warning off (which is not really recommended).
Users get the security prompts/exceptions because Outlook is configured on the client computer in one of the following ways:
Uses the default Outlook security settings (that is, no Group Policy set up)
Uses security settings defined by Group Policy but does not have programmatic access policy applied
Uses security settings defined by Group Policy which is set to warn when the antivirus software is inactive or out of date
Read more about that in the Security Behavior of the Outlook Object Model article.
I have recently put together a report for my business and I want to have it scheduled to run at 10pm to email end of play sales.
My macro and everything runs fine.. it copies a table as text from an excel file linked to the source data via Power Query, then the table is pasted into an Outlook Email and sent to the distribution list.
Is there a way to send this out without being logged in or have my PC switched on?
I have tried using the "Run whether user is logged in or not" and "Run with highest privileges", but it wont run the task when that is selected.
Is there something I'm doing wrong?
Here is my .bat code
cscript "Q:\Sales\SendEmail.vbs" "Q:\Sales\Sales.xlsm"
Here is my .vbs code
Set args = WScript.Arguments
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open args(0)
objExcel.Visible = True
objExcel.Run "send_email"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
Is there something I'm fundamentally missing?
I'm trying to take names of all windows user accounts. my code is working but it prints unnecessary user account also,
here is the code I'm using,
Dim query As New SelectQuery("Win32_UserAccount")
Dim searcher As New ManagementObjectSearcher(query)
For Each envVar As ManagementObject In searcher.[Get]()
Console.WriteLine(envVar("Name"))
Next
Output:
Administrator
DefaultAccount
Guest
Sam
WDAGUtilityAccount
Sam is the only user account I created on this PC. I can assume Administrator and Guest accounts come as default with windows. But DefaultAccount and WDAGUtilityAccount accounts are extremely unnecessary for printing in here. How can I prevent those unnecessary accounts printing from this code
As the Jimi's suggestion, I have updated my code by using Disabled property.
Win32_UserAccount class
Dim query As New SelectQuery("Win32_UserAccount")
Dim searcher As New ManagementObjectSearcher(query)
For Each envVar As ManagementObject In searcher.[Get]()
If Not envVar("Disabled").ToString.ToUpper.Equals("TRUE") Then
Console.WriteLine(envVar("Name"))
End If
Next
I have written the following piece of VB script which opens
an existing aplication xyz from the path I specfied.
The application (a custom windows application) opens succesfully.
(I would like to use the automation interface of this application
in my vb script.) for that I call CreateObject.
But, then I also get the error Activex component can't create object: 'xyz' for the line Set xyzObj = CreateObject("xyz").
The error is from this line, since if I remove this line there is no error.
Dim objShell
Set objShell = CreateObject( "WScript.Shell" )
objShell.Exec("C:\abc\def\xyz.exe")
Set xyzObj = CreateObject("xyz")
Set objShell = Nothing
You can't use CreateObject like that with a external program, started in your script or otherwise. CreateObject loads a COM-object that is registered on your pc. Google on vbscript and COM objects and you'll find plenty of info like at http://technet.microsoft.com/en-us/library/ee156598.aspx. If you want to interact with a started program you could use the sendkeys method or better use the autoit com object , see http://www.autoitscript.com/autoit3/docs/intro/ComRef.htm
I have a ftp server that i have written VBS scripts for, now I need an easy way to run them from my website. So i want to open my website, enter the username, password, users name and click submit, it must then run the VBS and insert the data and the VBS will then create the user on the FTP.
What is the best way to do this? should I load the VBS stuff into a application with webservice listener and build and execute it and then my site must communicate via the webservice, or should i rather build a local asp page and host it which when posted too runs the vbs file and gives it the data. Please explain how you would go about coding it if you leave a response :D
You could use
<%
Dim oWShell
Set oWShell = Server.CreateObject("WScript.Shell")
strCommand = "cmd.exe /c cscript C:\AbsolutePath\To\Your\VBSFile.vbs"
oWShell.Run strCommand, 1, true
Set oWShell = Nothing
%>
WShell and WShell.Run requires elevated access permissions on the web server. Make sure that the authenticated user (or IUsr) has those permissions.