I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. How can I do that?
this is my post build event:
call "$(ProjectDir)ExecOnGw.bat"
And this is my batch that if it runs in a normal command prompt, execution is ok.
c:\Sysinternal\psexec.exe \\gateway "C:\Remotepath\mybatch.bat" -u mydomain\myuser -p ******
pause
This batch calls another batch on a remote machine that does something, then if I want to exit, I have to press a "q" and "Enter". In a normal command prompt, it works fine. But in a Visual Studio post build event it goes down.
Help me!
I've done this before using the start command. I created a simple pause.bat file to demonstrate:
#echo off
pause Press Any Key
exit
If I put this in the post build event, I see a console that just closes.
call pause.bat
If I use this instead, I get a second console window that takes my input before closing.
start "My Process" /D c:\batch /WAIT pause.bat
Here is info about our technical development environment :
Microsoft Visual Studio Enterprise 2019
.NET Core 3.1
Just to add to #dsway good answer, I used Visual Studio 2019’s macros so that I could keep the directory path as relative:
start "My Process" /D "$(SolutionDir)Scripts" /WAIT blahblah.bat
Right-click on the Project in question
A context menu will show up
Select the Properties option
Select “Build Events”
Click on “Edit Post-build…”
Enter the aforementioned command that I posted above, and tailor it to your needs before pressing OK.
Related
I am in the middle of designing a schematic in Xilinx ISE 14.7 core generator and I've run into a little problem which I need help with. I need to run mem_edit.bat file in order to run the memory editor application and create a .coe file. Whenever I run the file, command prompt just flashes on the screen without running the commands. How do I run mem_edit.bat to be able to run memory test. I have run the file in a static command prompt session and inserted a pause in the code to no avail. I have also run the commands directly in command prompt and still no success. Please help me as I am on a timeline and I need to finish this fast. I am running on a 64 bit windows10 machine. I am kinda new to Xilinx ISE so please go a bit easy on me. The contents of mem_edit.bat have been quoted below
#echo off
REM Script to launch Xilinx memory editor
set CLASSPATH=
set JAVA_HOME=
"%XILINX%\java\nt64\jre\bin\java" -DXILINX="%XILINX%" -DMYXILINX="%MYXILINX%" -cp "%XILINX%\coregen\lib\encore.jar;%XILINX%\coregen\lib\coreutil.jar;%XILINX%\coregen\lib\sim.jar;%XILINX%\coregen\lib\xcc.jar;%XILINX%\coregen\lib;%XILINX%\coregen\resources" com.xilinx.iputils.memory.editor.CoreGen2RunMemoryEditor 2> NUL
I have managed to solve the issue. I happened to stumble on the directory where the ISE cmd short cut is saved C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Xilinx Design Tools 1\ISE Design Suite 14.7\Accessories. I run the file and Kaboom, the ISE cmd fired up. I entered mem_edit.bat and the application is up and running.
I have configured a Windows 7 VM as an agent to my TFS2015 setup.
I have created a Gradle (invoking the gradlew.bat) job to run my selenium scripts from the TFS build definition as
gradlew.bat clean test aggregate
This works fine (I can see IE being invoked) when I run it MANUALLY from the VM directly, BUT when the same is triggered as a job, it runs only in the background. Here are my observations:
The processes - Java, iexplorer, IEDriver.exe are all getting invoked in the Process manager.
When I kill iexplorer process, I can see the UnreachableBrowserException on the TFS console and the next test case runs.
The job with 2 test cases (approx 3-4 mins) fail after running for 10 mins and I see the error logs in TFS console
The scripts ran on UI the very first time I set this up but has never run after that.
I am using Gradle 3.0 and have disabled the Gradle Daemon by adding org.gradle.daemon=false in gradle.properties. This has been bugging me for a couple of days so badly.
Any help would be great.
For your tests to interact with the desktop they will need to be running interactively on a machine that is logged on and not locked (no screensaver active).
See: https://www.visualstudio.com/en-us/docs/build/admin/agents/v2-windows#interactive
You can configure the machine to start-up automatically and authenticate on start-up, disable the scren locking policy and screensavers and add the run.cmd to the windows start-up section in the star-menu.
See: http://donovanbrown.com/post/2015/08/28/auto-start-build-agent-in-interactive-mode
Press Windows Key + R to open the Run dialog
Type in the following and press enter:
control userpasswords2
Uncheck the box for User must enter a user name and password to use this computer.
Click the Apply button
You will be prompted by an Automatically sign in dialog
Enter the password for the user
Click OK
Click OK on the Users Accounts dialog
And
Right-click the desktop
Select New / Shortcut
Enter cmd
Click Next
Change the name to Start Agent
Click Finish
Right-click on the new shortcut
Select Properties
Append /c {pathTo\run.cmd} to the target
If you installed your agent to C:\Agent, your target should look like this: C:\Windows\System32\cmd.exe /c c:\agent\agent\run.cmd
Click OK
Note: updated for the 2.0 build agent, which is started using run.cmd instead of vsoagent.exe
Press Windows Key + R to open the Run dialog
Type in the following
shell:startup
Click OK
This will open the Startup folder in Windows Explorer.
Drag and drop the shortcut to this folder
I have 5 scheduled tasks that are scheduled to run every day at 9.30am. The schedule is basically a vbs script that opens an excel workbook and runs a macro. These 5 schedules can run fine if i run them seperately and 9 times out of 10 they run fine if I simulataneously run them from task scheduler. I do this by highlighting them all and then pressing run.
But sometimes when the task scheduler is doing its schedule they will fail. Sometimes all of them fail, sometimes some of them fail, but most of the time they all succeed.
Once I okay the errors(will post this next time it occurs) I can see the excel.exe in my Processes in TaskManager they are left hanging. I cannot see them in Applications because I run them in the background. Whilst here I know I can right click on the excel.exe and do a Create Dump file, but not sure what to do with this.
What I am interested here is discovering why they are failing? How do I debug it? Can I get a dump? how do i do this? I am sure the code is not perfect but the fact that they run fine seperately and most of the time fine together I am wondering is some memory resource getting used up at this time. This is what I would like to find out.
I know that i could space them out to run every minute, and this is something I might do but I would like to answer my questions above first.
Note: The vbs script in question can be found here in a previous question I asked.
EDIT1 Some useful links I have come accross following Noodles answer:
WinDBG: The very basics
question re: reading dump file
EDIT2
If i right click on check for a solution I can click on View Technical Details and that gives me:
`
Description
Faulting Application Path: C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE
Problem signature
Problem Event Name: APPCRASH
Application Name: EXCEL.EXE
Application Version: 14.0.7128.5000
Application Timestamp: 5398dfdc
Fault Module Name: EXCEL.EXE
Fault Module Version: 14.0.7128.5000
Fault Module Timestamp: 5398dfdc
Exception Code: c0000005
Exception Offset: 0023e751
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 5129
Additional Information 1: 8bde
Additional Information 2: 8bdedbea09a2027adb218b0e009eebf2
Additional Information 3: d4c1
Additional Information 4: d4c17b47443511f18e75ae920aa444bd
Extra information about the problem
Bucket ID: 361665432
`
EDIT3 : A useful walkthough example with commands
Crash Dumps
Load in Windbg. Then File menu - Open Crash Dump. Type !analyze (note wrong spelling)
Debugging
You can also start in a debugger.
windbg or ntsd (ntsd is a console program and maybe installed). Both are also from Debugging Tools For Windows.
Download and install Debugging Tools for Windows
http://msdn.microsoft.com/en-us/windows/hardware/hh852363
Install the Windows SDK but just choose the debugging tools.
Create a folder called Symbols in C:\
Start Windbg. File menu - Symbol File Path and enter
srv*C:\symbols*http://msdl.microsoft.com/download/symbols
then
windbg -o -g -G c:\windows\system32\cmd.exe /k batfile.bat
You can press F12 to stop it and kb will show the call stack (g continues the program). If there's errors it will also stop and show them.
Type lm to list loaded modules, x ! to list the symbols and bp symbolname to set a breakpoint
If programming in VB6 then this environmental variable link=/pdb:none stores the symbols in the dll rather than seperate files. Make sure you compile the program with No Optimisations and tick the box for Create Symbolic Debug Info. Both on the Compile tab in the Project's Properties.
Also CoClassSyms (microsoft.com/msj/0399/hood/hood0399.aspx) can make symbols from type libraries.
You can schedule this command line instead.
Autostarting Programs in Debugger
You can also make windbg attach to any specific program when started. See gflags.exe. Only in GUI mode.
Errors
Also get the error number. TS keeps a history of runs and their errors. TS has a history tab.
.
Currently working on a WCF service running as a windows service.
I've made an installer and written a little script which adds a user account for it to run under and then registers and starts the service under than account. And a build step in visual studio to copy it to a discrete folder so we're not running directly off the solution. All works fine.
However, as I extend and improve this service, testing it is becoming a bit of a pain. Each time I want to check my changes I have to stop the service, rebuild, re-start the service and re-attach visual studio to the process before I can step through.
Just wondering if there's a quicker or better method of doing this without writing some proxy host for all the services? Unit tests won't cut it in this instance because the service needs to do system-ish stuff like connecting to Active Directory endpoints.
I know this question is ancient, but I recently solved part of this using build events as follows:
Pre-build event:
if "$(ConfigurationName)" neq "Debug" goto NoStop
echo Attempting to stop windows service MyService
net stop MyService > MyService.log
if "%errorlevel%" neq "0" (call )
type MyService.log
:NoStop
Post-build event:
if "$(ConfigurationName)" neq "Debug" goto NoStart
findstr "/c:stopped successfully" MyService.log >nul
if "%errorlevel%" equ "0" net start MyService
(call )
:NoStart
Features of this approach:
The configuration is checked and if I'm not building in Debug, then the whole bit is skipped.
The NET STOP command will try to stop your service and the if command below it will swallow any errors that might occur. This is great if your service isn't installed or if it isn't running.
Since the service is stopped, the service EXE is unlocked and the build doesn't fail with those annoying "file is locked" errors.
The post-build event will only start the service if the pre-build event was successful in shutting it down. The FINDSTR command searches the log file created during the pre-build event for the string "stopped successfully." If it is found, the NET START is called. Either way, errors are swallowed by the (call ) on the next line.
This is working for me in Visual Studio 2015 running on Windows 7. Hope this helps somebody!
I'm currently using CruiseControl.NET to automate my build. We have two different ways to build a solution in my build environment - one is through the Keil uVision4 IDE, the other is through Visual Studio 2008.
I've successfully gotten the Visual Studio solution to build properly using CruiseControl.NET and have created a batch file which properly uses Keil's uVision command line interface to compile my uvproj Project (compilation details here).
Problem Description
1) I can successfully execute the build script on my Windows 2008 server and build the project if I create a command prompt with administrator privileges (I'm doing this manually - start -> run -> cmd with ctrl-shift-enter to run as admin).
2) However, if I create a command prompt without administrator privileges, and attempt to execute the batch file, the batch file won't work unless I accept the prompt asking me to confirm admin rights are required to run the batch script.
How do I automatically execute a batch file as an administrator through CruiseControl?
Is this something that could be automated using the RunAs command?
Technical details
1) The batch file being executed is pretty simple - it deletes the old output and re-makes the output, creating a build log file in the location below.
set BuildLogLocation=BuildLog\BuildLog.txt
echo on
cd ../..
cd PTM
rmdir /s /q output
mkdir output
mkdir BuildLog
C:\Keil\UV4\UV4.exe -r myProj.uvproj -o %BuildLogLocation%
echo ErrorLevel of build is %ERRORLEVEL%
echo build complete, see %BuildLogLocation%
2) Currently I'm looking to use the Exec functionality to run the Keil build script above:
<Exec>
<Command>C:\myProject\Build\KeilBuild\BuildScript.bat<Command/>
<buildTimeoutSeconds>600<buildTimeoutSeconds/>
<!-- Details about error codes can be found here:
http://www.keil.com/support/man/docs/uv4/uv4_commandline.htm -->
<successExitCodes>0,1</successExitCodes>
<Exec/>
Related questions:
How can I use a build server with Keil uVision4 (MDK-ARM), script a build, use a makefile? (Electrical Engineering)
Execute a command-line command from CruiseControl.NET (Stack Overflow)
Can you run CCService, the CruiseControl.NET Windows Service, as a user who has administrative permissions? I'd try that first.
If that doesn't work, I would use runas to run your script. You'll have to embed the administrative user's password in the script calling runas.
I know this is old but, Did you get an offical way to do it Via Cruise Control?
Normally I create this and call it to call other processes "As Admin".
Make a ".VBS" script with This in the contents:
Dim strBatchPath
strBatchPath = "PATH-TO-FILE.EXE"
Set runBatch = CreateObject("shell.application")
runBatch.shellexecute strBatchPath,,,"runas",1
That could be an option to people that can't find an official way
You could try psExec from sysinternals. If you don't need to run as a nt-authority account you should be able to use this in the same way as runas.
It allows you to pass in the username/password as a switch (if memory serves)
I have Discovered that when using PSEXEC and using the -h switch, it then "runs as admin" on destination
e.g.
psexec -h \ServerToRunOn /accepteula -u DOMAIN\USER -p PASSWORD "PATH-TO-FILE"
I am Using CC.Net to call a batch file with the above in. This will run that file as Admin