How do I run edge on login in Group policy &/Or login script - authentication

I am trying to run edge on all client machines when they log in. This is easily done with IE as you just set iexplore.exe in the Startup section of Group Policy but not having much luck with Edge.
I have tried creating a .bat / .cmd and trying to call it
Code:
#echo off
start microsoft-edge:https://google.ie/
I know the above works as Edge opens up when i double click the cmd/bat
I am trying to call this from within a login.vbs script but am having no joy, any ideas? or alternatively if anyone has been able to get this working in Group policy? Thanks.
VBS Code:
Function Edge()
dim shell
set shell=createobject("wscript.shell")
shell.run "\\ipbdc3\SYSVOL\ipbdomain.local\scripts\edge.cmd"
set shell=nothing
End Function

Related

Shell hitting Run-Time error '5' trying to call R script in Access VBA

I made a simplified version of my code that directly highlights the issue.
I have read dozens of similar issues/solution.
Part of my workflow in VBA in Microsoft Access involves calling an R script that does some logic and returns information to a table in the same database.
It was working until we moved the location of the R installation to a new drive. Changing the path to this new install location does not work. No other code is changed.
cmd = "C:\R\bin\i386\Rscript.exe C:\R\test.R"
Debug.Print cmd
Shell cmd
I get
runtime error '5'
I am using the immediate window to check the paths are correct and copying them into RUN to verify that they do work.
The above outputs:
C:\R\bin\i386\Rscript.exe C:\R\test.R
It works in RUN.
The first thing I found when searching online is to add more (") as shell can handle them weirdly:
cmd = """C:\R\bin\i386\Rscript.exe""" & " " & """C:\R\test.R"""
Or any iterations of using "s in different places, output:
"C:\R\bin\i386\Rscript.exe" "C:\R\test.R"
Same error but works in RUN. I also tried them all successfully in CMD.
It seems just Shell refuses to launch R from that path. I have moved it elsewhere on my C drive with same effect.
I cannot recreate the original R installation path as that shared drive is now completely dead.
EDIT:
I changed to using ShellExecute simply to try and make Notepad ++ open, again works in cmd.
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\N\notepad++.exe", "C:\R\test_in.csv", "", "open", 1
This time I hit a "suspicious macro error" that leads me to believe that it may be an antivirus setting (macros are enabled in Access) blocking Shell from calling anything.
After days of testing I have found the solution, hopefully this can help anyone else in a similar situation. Windows Defender only blocks shell calls to non-Microsoft products, so I nested a call to PowerShell within the call to Shell:
Shell ("powershell.exe C:\R\bin\i386\Rscript.exe C:\R\test.R")
Take note you need to play around with the "s a lot ot get it working, my actual pipeline has more arguments and I had to enclose them in 5 sets of "s for it to pass through to powershell properly. IE:
Dim codePath As String: codePath = """""\\example\example"""""
Try these variations using Start or a second Command:
cmd = "Start C:\R\bin\i386\Rscript.exe C:\R\test.R"
or:
cmd = "cmd /c ""C:\R\bin\i386\Rscript.exe C:\R\test.R"""

Is there a way to write a command directly by code in the immediate window?

I'm trying to save all lines from the output window into a log-file. That works fine when I enter the command directly into the immediate window. However, I need a way to enter the command line by code.
I searched for a way to enter a command into the immediate window so the log-file I want will be created and filled with data. That's not happening and I don't know if this is even possible. Searching Google didn't help so far.
My command line is:
> Tools.LogCommandWindowOutput C:\Users\user\AppData\test.log
And I try to get it into the immediate window by
Debug.Print("> Tools.LogCommandWindowOutput C:\Users\user\AppData\test.log")
The command line works fine when put directly into the immediate window (either by typing it in or pasting it in). When I try to do that by code, nothing happens. Is there a way to do that or do I have to try another option and if so, what option is it?
EDIT:
I've tried the solution provided by RobertBaron with the following changes:
'Dim dummy = $"C:\\log\\outputfileAddOn_{Date.Now:yyyy_MM_dd_HH_mm_ss}.log"
'cmdWindow.SendInput($"Tools.LogCommandWindowOutput {dummy}", True)
cmdWindow.SendInput("Tools.LogCommandWindowOutput C:\log\outputfile_AddOn.log", True)
(I want a new file to be written every time, so I tried to add the date at the end to have unique file names)
It creates the file but doesn't log anything in it. What do I do wrong?
Another solution I have found was to add a command parameter in project-properties-debug-command parameter:
> C:\log\outputfile.log
This creates the file and inserts all of the data from the output window. The only problem that I have now is that this file will be overwritten every time the program is started. Is there a way I can set the logging from the second, third, … start at the end of the file? (adding /on at the end of the command Parameter didn't help) Or can I provide something like "outputfile_yyyy_MM_dd_HH_mm_ss.log" (for example: outputfile_2019_07_23_15_47_45.log)?
Thank you for your help!
You need to create a Visual Studio Extension project.
Add a new Custom Command item to the VSIX project.
This will create the Command1.vb. This is where you implement the code that you want to execute inside Visual Studio. The code executes whenever you select the entry Invoke Command1 from the Tools menu.
At the bottom of the Command1.vb file, there is the Execute() Sub. It displays a message just to show that the command is working. You can remove this eventually. But for now, just run the project. Another instance of Visual Studio will start. This is where you can test and debug your code. Once the second instance of Visual Studio has started, go to its Tools menu, and select the Invoke Command1 entry. A message box will display. Stop execution.
Now we want to modify the Execute() Sub so that our code gets executed when Invoke Command1 is selected. Here is the Sub that will execute the command that you want. Add it to the Command1 class.
Public Sub ExecCommandWindow()
Dim dte As EnvDTE.DTE = CType(Microsoft.VisualStudio.Shell.Package.GetGlobalService(GetType(Microsoft.VisualStudio.Shell.Interop.SDTE)), EnvDTE.DTE)
Dim cmdWindow As CommandWindow = CType(dte.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow).Object, CommandWindow)
'Display some text in the command window
cmdWindow.OutputString("Executing command from the automation OM...")
'Send some command strings to the command window and execute them...
'This command will start logging all input/output in the command window to the specified file
cmdWindow.SendInput("Tools.LogCommandWindowOutput cmdwindow.log", True)
''Open a file in a code editor:
'' 1. We use an alias, 'of', for the File.OpenFile command
'' 2. This command takes quote-delimited parameters (in this case,
'' the name of the editor to load the file in)
'Dim cmd As String = "of "
'cmd = (cmd + """""C:\Contoso\ContosoCommonFramework\Integration.cs""""")
'cmd = (cmd + "/e:""""CSharp Editor""""")
'cmdWindow.SendInput(cmd, True)
'cmdWindow.SendInput("Edit.Find MessageTrxId", True)
'Turn off logging
cmdWindow.SendInput("Tools.LogCommandWindowOutput /off", True)
End Sub
Change the Execute() Sub to call ExecCommandWindow().
You can change the name of the command by changing its title in the Command1 class.
The Visual Studio extension needs to be installed by each user. Just distribute the .vsix file. To install, double-click it.
It's not the best solution, but it works (for now):
adding
>> C:\log\outputfile.log
(with two '>' before the path for the log file) attaches every log at the end of the file. So I get all Information and nothing is being overwritten.
As I want to know if there is a better solution, I will keep this thread open if that is permitted.

wshshell.popup not being displayed to other user when using task scheduler

I've got a tricky thing to do here.
I'm using task scheduler to auto-reboot all the computer during the weekend by calling a simple .bat file containing a shutdown command.
I wanted to give the user the possiblilty to cancel that reboot by displaying them a popup saying "Computer is about to restart, do you wish to continue ? Ok or Cancel". I have done that with VB using the popupbox method, it works perfectly.
Here is the problem i'm facing: The task is running under the System account and unless the task is set to run with the current logged on user, the popup box won't appear. I could change the account set in the task but I've got hundreds of users so impossible.
I've done some kind of a workaround, calling the VBS from Psexec... Works, but it's not perfect.
Here is my Psexec command that calls the VB:
Psexec -accepteula -s -i cmd /c C:\Windows\System32\Weekly_Reboot.vbs
Here is my VB:
Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Computer is about to restart, do you wish to continue?", 30, "/!\ Weekly Restart /!\", 4 + 32)
Select Case BtnCode
case 6
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\Windows\System32\Weekly_Reboot.bat"
case 7
WScript.Echo "No prob - the computer won't restart"
case -1
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "c:\Windows\System32\Weekly_Reboot.bat"
End Select
And here is the actual reboot command:
Shutdown /f /r /c "This is the weekly reboot"
Any idea would be really awesome ! I really tried googling it, but no luck.
Here is the problem i'm facing: The task is running under the System account and unless the task is set to run with the current logged on user, the popup box won't appear. I could change the account set in the task but I've got hundreds of users so impossible.
Change the task to run under the group called Users. It will make the task run for any logged in user.
I'm not certain if this is needed: but you might want to run it using the highest privileges.

Call .reg File from Excel-VBA script

I want to call a .reg File out of my VBA script. I'm using Office/Excel 2013.
I know Excel can't run these files by itself, so i need to call the file via shell. The code i wrote doesn't work:
Sub deactivateHyperlinkWarnings()
Dim x
x = Shell("cmd /C C:\TEMP\DisableHyperlinkWarnings.reg")
End Sub
I found this piece of code somewhere on the web, but its not working. I don't even get an error message. The .reg File is located in C:\TEMP
What do i need to write to make it work?
Plus: Is it possible to suppress the MessageBoxes that are displayed when i run the .reg-File? When i start the file manually, i need to Hit "OK" like 3 Times. The people who are working with the Excelsheet later on shouldn't be seeing these things.
Instead of running cmd try to run reg. So in your case it should be x = Shell("reg import C:\TEMP\DisableHyperlinkWarnings.reg")
More info here

How to capture the contents of DOS based executable file dynamically which keeps open for processing?

Team,
I would appreciate your help on this,
Background of my project: I have a executable file e.g. abcd.exe which is actually a kind of server which opens itself in a MS DOS window and once launch, it keeps running. As mentioned since it is a server, it keeps logging some log traces and keeps adding new lines in DOS window one by one. This server needs some parameter to start so here the parameter is path of configuration file wherein all the config details are saved. So, to start this server, I need to provide in command prompt,
*Start > Run > CMD
abdc.exe -lookup "C:\MyServer\Bin\designConfig.properties"
To avoid manual steps, I have created batch file e.g. abcd.bat with below lines
"TITLE: MY SERVER - NODE 1234 (SERVER)"
abdc.exe -lookup "C:\MyServer\Bin\designConfig.properties"
My Machine and specification
Above mentioned abdc.exe file is a 64 bit server. My OS: Windows 7 64
Bit Platform: VB Visual Studio 2012 or MS Access VBA
My Requirement
Now I have created a VB Form, multiple line textbox & button. I want,
Once I click on that button, it should lookup the executable file or batch file and launch the abcd.exe server program by accepting the parameter. (I am done with this using below code)
=======================
Dim abc As New Process
Dim abcinfo As New System.Diagnostics.ProcessStartInfo
abcinfo.FileName = "C:\ABCD\abdc.bat""
abcinfo.RedirectStandardOutput = True
abcinfo.RedirectStandardError = True
abcinfo.UseShellExecute = False
abcinfo.ErrorDialog = False
abc.StartInfo = abcinfo
abc.Start()
Dim abclog As System.IO.StreamReader = abc.StandardError
abc.BeginOutputReadLine()
TextBox1.Text = abclog.ReadToEnd()
abc.WaitForExit()
=======================
This opens up the executable file i.e. server but CMD screen appears as blank and I have close it to check the details in textbox. Once I close it, textbox displays the contents of the ABC server which is just closed. I can have the contents but my server is not running now!!
So I want that once I click the 'Start Server' button, (a) it should launch the exe program i.e. server, (b) keep the window invisible (the dos window it uses should not be visible to user nor should minimized on taskbar.) (c) Captures the contents of that DOS window and display them in the textbox on my form (d) Most important, update the contents of the abc server whenever new traces are logged in the server screen i.e. new line added on DOS screen.
Basically, I will be having multiple instaces of this server intance and I dont want users to see at every instance to check the logs. Once they select perticular abc server instance from listbox, textbox should display the live contents from associated DOS executable window.
I have searched lots of thread but did not find the answer. Any help would be greatly appreciated!!!
P.S: This server is developed in C and I believe is not a console application.
Thanks, Prashant
Sorry, but I couldn't quite figure out what you are trying to do, but if you want to redirect output in DOS-window (=cmd.exe), here's how to do it:
your.exe yourparameter1 yourparameter2 >redirect_here.log 2>&1
The first > redirects the sysout to redirect_here.log -file and the 2>&1 redirects the syserr to the same file.
If you want to track what is written to the redirect_here.log -file in another DOS-window, you need to use tail.exe. If I remember correctly, you can find the tail.exe in Windows Resource Kit, but I use one bundled with UnxUtils. It's a zip -package, the tail.exe is found in \usr\local\wbin\ -folder along with other useful tools. Here's how use tail.exe:
tail -f redirect_here.log
The -f -switch means that you want the tail.exe to show the new lines as they appear in the redirect_here.log.