getting windows user account (profiles) list - windows

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

Related

Running an Excel Macro Overnight When Logged Off and Shut Down using Task Manager

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?

Start Domino service and word

I want to modify a word document from an agent in Lotus Script. Domino server starts as a service with an Administrator user count. The word document is attached in a Lotus Notes document. I extract the document in a folder that Domino has access.
When the Domino server (as service) runs the process, the Domino displays an error. But when I start the Domino server as application, the process runs well and it doesn't get any error.
The script code is the next:
Set rtItem = doc_perfil.GetFirstItem(campo)
Set obj = rtitem.EmbeddedObjects(0)
sFile = RUTA + "\" + ReplaceSubstring(nameNewFile, "/", "-") + ".docx"
Call obj.ExtractFile(sFile)
OLE_OBJECT = "word.application"
Set Word = CreateObject (OLE_OBJECT)
Set templt = Word.Documents.Add (sFile)
The line that produces the error is "Set templt = Word.Documents.Add (sFile)"
As a first point, running Word on a server is totally unsupported by Microsoft.
The quick and dirty way round this is to not run Domino as a service. A service can't interact with the UI which it needs to for OLE.
The downside to this is that the Domino Server will need to be manually restarted if the Windows server ever reboots.
The proper way to do this is to do what you need in java using a library like docx4j or Apache POI. As you don't include any code beyond opening the word doc, I can't comment further on what would be a suitable library.
In the line of code,
Set templt = Word.Documents.Add (sFile)
Add, does not take parameters, please try word.documents.open
If the Domino is not run as a service and still the error occurs, change the security level of the agent to 3 (run will full admin rights)

How do I stop the user from manually closing a VB6 automated instance of Word?

My question is about absolute control over automated instances. I'm using VB6 to automate the generation of forms used in our workplace. The app is in Beta and I've written a User Manual to introduce the application to new users; explaining the sub-functions of the GUI. I use a command button on the GUI to open and close the User Manual in an instance of Word. All this is fine until the user closes the Word app manually while the app is running. This kills the Word instance, but I need to either stop the user from closing the Word instance, or have the app realize the instance is gone. My automation knowledge is pretty shallow. I adapt sub routines from VBA macros. Please help.
I need to either stop the user from closing the Word instance, or have
the app realize the instance is gone
You can do both - declare your Word variable using the "Give me events" syntax and it will raise the DocumentBeforeClose event in your code.
Public WithEvents mWordApp As Word.Application
Sub DoStuff()
Set mWordApp = New Word.Application
'// open doc ...
mWordApp.Visible = True
End Sub
Private Sub mWordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
Cancel = MsgBox("Word is closing, keep open?", vbYesNo) = vbYes
End Sub
The "... WithEvents ..." declaration of the MSOffice Application instance is the solution to this problem. The event list for the app allows the programmer full automated control of the instance from behind the curtain. Thanks all!

How to protect database credentials in uft

I have this connection string in library to connect to sql server.
Function db()
connectionnameDev = "Description=connect to hh dev;DRIVER=ODBC Driver 13 for SQL Server;SERVER=xxx;UID=xxx;PWD=#xxx%;Trusted_Connection=No;APP=UFTBase;WSID=L-XP9550-xxx;"
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open connectionnameDev
End Function
This library is shared across the team. Now, everyone has access to the credentials. Each person has own database credentials. When they run scripts, they should run with their own credentials. What would be the correct approach to protect the database credentials so each person can run scripts with their own credentials?
If this is part of a framework, here's one idea we used in one of the teams I worked at. Our framework loaded multiple function libraries from ALM, but there was one function library that was always locally referenced, called "Load_myCredentials.qfl".
Each team member can have their credentials saved as global parameters/variables in a qfl file in their local C: drive, and the framework can just load this as a function library. Then the password becomes available throughout the test, yet the password does not become visible in any results. All you have to do is change the first line of your function db(), and parameterize the password part.

Remotely turn off Sharing Wizard in Windows 7

I am trying to figure out the registry key in Windows 7 that will turn off Sharing Wizard for a computer (not just a user).
Is this the key?
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\SharingWizardOn
But here is my problem, there are many values, and I don't know which one to change to Disable the Sharing Wizard on the Windows 7 computer
Which key do I change to 0?
First, it isn't the key
HKEY_USERS\<userId>\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\SharingWizardOn
but the REG_DWORD value called SharingWizardOn in the key:
HKEY_USERS\<userId>\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
Second: replacing <userId> in the above path with .DEFAULT will only set it for new user accounts subsequently created (HKEY_USERS\.DEFAULT is used to initialise the new user's registry settings).
To set it for all users you need to change for each existing user profile. This can be done by setting for each user (represented by their security ID – SID – rather than their user name). Iterating through all the subsekeys of HKEY_USERS that *do not end with _Classes would work.
Here the value looks like this in regedit (for my account, hence the path starting HKEY_CURRENT_USER which is just an alias for HKEY_USERS\<My Account SID>):
Yes sure, you are rigth!
Apply For all users
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\SharingWizardOn
Just change ..
CheckedValue to 0
And thats all
You do not need to restart!

Resources