Remove usb drive using cli, on success remove turn off the windows - windows

I wondering to make a batch file that have purposed like this :
when a usb drive that ejected on my notebook is succesfully unmount, I want to make my windows is shutdown.
So, I use RemoveDrive.
Assumed, I mounted my flash drive to E, I use this command
RemoveDrive.exe E: -L
it gives me message like this :
Removing 'My drive'(E:)
success
Now, I was wondering to make a batch file (.bat), when success, it execute 'shutdown / s'. if failed, it gives me just a message error. How come ?
Amy help it so appreciated.
Edit :
based this web : FAQ
it said :
0 - successfully removed a device
1 - device identified but not removed
2 - device not found or parameters are invalid
4 - RemoveDrive.exe located on the drive to remove -> temporary copy
created and executed
so this is my code so far :
#ECHO OFF
set def="0"
SET /P uname=Enter the drive (letter:):
IF "%uname%"=="" GOTO Error
RemoveDrive.exe "%uname%" -L
if %ERRORLEVEL% == def
shutdwon /s
else
echo 'Something have problem'
GOTO End
:Error
ECHO Please enter your drive's name!
:End
if success or failed, it still gives me the syntax of command is inicnorrect message

As per if command syntax and explanation in Command-Line Reference:
if %ERRORLEVEL% == def (
shutdown /s
) else (
echo 'Something have problem'
)

Related

Does JanusGraph run on Windows 10

Windows 10, janusgraph-0.2.0-hadoop2.
I have put the winutils.exe in the bin folder.
P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\bin>gremlin-server.bat
Error: Could not find or load main class Files
I had a quick look at the bat script and added some echo statements:
echo "%1"
IF "%1" == "-i" (
GOTO install
) else (
GOTO server
)
:: Start the Gremlin Server
:server
IF "%1" == "" (
SET GREMLIN_SERVER_YAML=%JANUSGRAPH_HOME%\conf\gremlin-server\gremlin-server.yaml
) ELSE (
SET GREMLIN_SERVER_YAML=%1
)
java %JAVA_OPTIONS% %JAVA_ARGS% -cp %CP% org.apache.tinkerpop.gremlin.server.GremlinServer %GREMLIN_SERVER_YAML%
echo %JAVA_OPTIONS%
echo %JAVA_ARGS%
echo %CP%
echo %GREMLIN_SERVER_YAML%
echo "call to GremlinServer"
The output:
P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\bin>gremlin-server.bat
.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\slf4j-log4j12-1.7.12.jar;;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-all-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-berkeleyje-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-bigtable-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-cassandra-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-core-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-cql-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-es-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-hadoop-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-hbase-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-lucene-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-solr-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\*;
""
Error: Could not find or load main class Files
-Xms32m -Xmx512m -Djanusgraph.logdir=P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\log -Dtinkerpop.ext=P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\ext -Dlogback.configurationFile=conf\logback.xml -Dlog4j.configuration=file:/P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\conf\gremlin-server\log4j-server.properties -Dlog4j.debug=true -Dgremlin.log4j.level=WARN -javaagent:P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\jamm-0.3.0.jar -Dgremlin.io.kryoShimService=org.janusgraph.hadoop.serialize.JanusGraphKryoShimService
ECHO is off.
.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\slf4j-log4j12-1.7.12.jar;;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-all-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-berkeleyje-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-bigtable-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-cassandra-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-core-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-cql-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-es-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-hadoop-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-hbase-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-lucene-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\janusgraph-solr-0.2.0.jar;P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\lib\*;
P:\Software\DB\NoSQL\janusgraph-0.2.0-hadoop2\conf\gremlin-server\gremlin-server.yaml
"call to GremlinServer"
This question was also asked on the janusgraph-users Google Group, and I've copied my answers here:
JanusGraph does run on Windows 10. The user experience is not ideal,
and could use some help with people with Windows expertise. I've
opened up issue
950 to track
making the prepackaged distribution more Windows-friendly.
Your problem is probably coming from your CLASSPATH variable, and
I'd think that ".;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip;" is messing it up because of the
spaces in the path. Try unsetting the CLASSPATH before running
gremlin-server.bat.
The default Gremlin Server configuration uses
janusgraph-cassandra-es-server.properties because the pre-packaged
distribution bin/janusgraph.sh start will start a single node
Cassandra, a single node Elasticsearch, and the Gremlin Server. If you
want to run with Cassandra, you could go a version directly from the
Apache Cassandra site or a Datastax distribution if you want to go
with an MSI installer. If you're not interested in using Cassandra,
you could change the gremlin-server.yaml to use the
janusgraph-berkeleyje-server.properties which is pretty good for
getting started.

Error MSB3073 in postbuild event VS2013

In the process build of a huge enterprise C# VS2013 sometimes I get the error MSB3073 after the in the post build event. Unfortunately all the answers on this topic did not tackle exactly this problem.
The error message is the following:
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4548,5): error MSB3073: The command "#call "D:\TFS\SUV\Dev\2.2.28\DotNet\GUI\Allianz.Vita.Web.SUV\Allianz.Vita.Web.SUV.Post-Build.cmd" D:\TFS\SUV\Dev\2.2.28\DotNet\GUI\Allianz.Vita.Web.SUV\ " exited with code 1073750991.
I was not able to find a criterion to reproduce it sistematically, I only figured out it never happens if I run Clean before Rebuild. Setting verbosity of the MSBuild log to diagnostics did not give me any clue.
The last statement of the cmd file executed in the post build is "SUCCESS", which appears in the log.
Here is the log of a failed build
ERRORLEVEL = 0 (TaskId:2172)
SUCCESS ! (TaskId:2172) ==> end of Allianz.Vita.Web.SUV.Post-Build.cmd file
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4548,5): error MSB3073: The command "#call "D:\TFS\SUV\Dev\2.2.28\DotNet\GUI\Allianz.Vita.Web.SUV\Allianz.Vita.Web.SUV.Post-Build.cmd" D:\TFS\SUV\Dev\2.2.28\DotNet\GUI\Allianz.Vita.Web.SUV\ " exited with code 1073750991.
Done executing task "Exec" -- FAILED. (TaskId:2172)
Here is the log of a successful build:
ERRORLEVEL = 0 (TaskId:2172)
SUCCESS ! (TaskId:2172) ==> end of Allianz.Vita.Web.SUV.Post-Build.cmd file
Done executing task "Exec". (TaskId:2172)
Done building target "PostBuildEvent" in project "Allianz.Vita.Web.SUV.csproj".: (TargetId:3611)
Target "CoreBuild: (TargetId:3612)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets" from project "D:\TFS\SUV\Dev\2.2.28\DotNet\GUI\Allianz.Vita.Web.SUV\Allianz.Vita.Web.SUV.csproj" (target "Build" depends on it):
Done building target "CoreBuild" in project "Allianz.Vita.Web.SUV.csproj".: (TargetId:3612)
The error number 1073750991 looks more as a memory pointer that to a coded value. Does the couple of numbers Microsoft.Common.CurrentVersion.targets(4548,5) have a meaning ?
Sorry for the long description, I will be very grateful for any hint.
The cmd file in question basically does this:
nmake.exe %PROJECTDIR%\Allianz.Vita.Web.SUV.Post-Build.mak
echo ERRORLEVEL = %ERRORLEVEL%
and Allianz.Vita.Web.SUV.Post-Build.mak basically is a sequence of xcopy statements as
#xcopy /R /Y .....\FRAMEWORK\Deploy\Allianz.Framework.Security.dll.config .\Bin\
None of them reports (apparently) an error.

subinacl get full output

We are using the windows console program subinacl.exe to grant a user the right to stop and start a service. Therfore we use the following command:
subinacl.exe /service %SERVICE_NAME% /grant=%PC_NAME%\%USER_NAME%=PTO
where
%SERVICE_NAME% = name of the service
%PC_NAME% = name of the computer
%USER_NAME% = name of the user that should become the right to start and stop the service
PTO = right to start and stop the service (R would be just reading)
When typing the command into the default windows command line (with administrator rights) on a windows server 2012 the result is:
ELITE_INETRSVSERVER : delete Perm. ACE 4 test-pc\test
ELITE_INETRSVSERVER : new ace for test-pc\test
ELITE_INETRSVSERVER : 2 change(s)
Elapsed Time: 00 00:00:00
Done: 1, Modified 1, Failed 0, Syntax errors 0
Last Done : ELITE_INETRSVSERVER
Now we want to save the text into a file or get it into a programm (via redirect the outputs : Getting output from a shell/dos app into a Delphi app). We need the integer values of Done and Failed found in the result.
The problem is, that we cannot catch the last three lines after the empty lines.
When using console redirect, the first three lines can be found in the file result.txt. But the last three are shown in the console.
subinacl.exe /service %SERVICE_NAME% /grant=%PC_NAME%\%USER_NAME%=PTO > result.txt 1<&2
The same problem we do have, when redirecting the output programmatically.
Of course every command is executed as administrator.
The option /errorlog could help to solve the problem:
subinacl /outputlog=c:\NONERRORS.TXT /errorlog=C:\ERRORLOG.TXT /file C:\TEST.TXT /display
if C:\ERRORLOG.TXT file is empty it means that the command has been executed successfully.

Windows copy command return codes?

I would like to test for the success/failure of a copy in a batch file, but I can't find any documentation on what if any errorlevel codes are returned. For example
copy x y
if %errorlevel%. equ 1. (
echo Copy x y failed due to ...
exit /B
) else (
if %errorlevel% equ 2. (
echo Copy x y failed due to ...
exit /B
)
... etc ...
)
I'd opt for xcopy in this case since the error levels are documented (see xcopy documentation, paraphrased below):
Exit code Description
========= ===========
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred. There is not
enough memory or disk space, or you entered
an invalid drive name or invalid syntax on
the command line.
5 Disk write error occurred.
In any case, xcopy is a far more powerful solution. The equivalent documentation for copy does not document the error levels.
As an aside, you may want to rethink your use of the %errorlevel% variable. It has unexpected results, at least in some versions of Windows, if someone has explicitly done something silly like:
set errorlevel=22
In those cases, the actual variable will be used rather than grabbing the actual error level. The "normal" way of doing this is (in decreasing order since errorlevel is a "greater than or equal to" check):
if errorlevel 2 (
echo Copy x y failed due to reason 2
exit /B
)
if errorlevel 1 (
echo Copy x y failed due to reason 1
exit /B
)
In addition, if you are running Win7 or Win Server 2008 or later, you should look into Robocopy, which is now the preferred mass-copy solution.
It might also be worth pointing out that xcopy doesn't always return the error code you expect.
For example when trying to copy multiple files with a wildcard but there are no files to copy you expect a return error code of 1 ("No files were found to copy"), but it actually returns 0 ("Files were copied without error")
C:\Users\wilson>mkdir bla
C:\Users\wilson>mkdir blert
C:\Users\wilson>xcopy bla\* blert\
0 File(s) copied
C:\Users\wilson>echo %ERRORLEVEL%
0
I believe Copy only returns 0 for success or 1 for failure.
XCopy has documented return codes:
0 = Files were copied without error.
1 = No files were found to copy.
2 = The user pressed CTRL+C to terminate xcopy.
4 = Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 = Disk write error occurred.
There is also one point I would like to emphasize: xcopy as well as robocopy can only copy files, but they can't rename them.
While looking at the original situation (copy x y, which looks like a rename to me), I have the impression that the copy command still is the only one suitable for this purpose.
Error# Description
0 No error
1 Not owner
2 No such file or directory
3 Interrupted system call
4 I/O error
5 Bad file number
6 No more processes
7 Not enough core memory
8 Permission denied
9 Bad address
10 File exists
11 No such device
12 Not a directory
13 Is a directory
14 File table overflow
15 Too many open files
16 File too large
17 No space left on device
18 Directory not empty
999 Unmapped error (ABL default)

Detect a broken internet connection using windows batch programming

I'm using an internet connection which goes down after some time. If I repair my connection it works fine. I have to do it always manually. I want to do this task automatically.
I.e. I want to create a windows batch file which is constantly running in the background. When my internet connection is down, it will renew and restart the connection again without any interaction
I want to do this task using a windows batch file. I tried this:
runas /user:local\administrator
ipconfig /release
ipconfig /flushdns
ipconfig /renew
However, I don't know how to detect whether Network connection is down or up?
I'm hoping for quick and positive response.
I made this some time ago. I think that will help you. (but in is spanish)
https://github.com/edgardok/Arregla_Internet/blob/master/ARREGLA.INTERNET.bat
:INICIO
IF EXIST respuesta.tmp DEL respuesta.tmp >nul
PING %DIRECCIONREMOTA% > respuesta.tmp
FIND /C /I "perdidos = 0" respuesta.tmp >nul
GOTO CASO%ERRORLEVEL%
:CASO1
REM ***conexion fallida***
ECHO %date% %time%. NO ESTA HABILITADA LA PLACA DE RED O NO FUNCIONA.
GOTO menu
:CASO0
REM ***conexion OK***
ECHO %date% %time%. Conexion ok.
GOTO menu
You could try and ping a widely used service in your country (or ping google like crazy) to detect internet connectivity. it's not bullet proof, but will let you know when your internet is down (probably).
The result of pinging could be checked by batch/script and according to the result, decide whether you want to ipconfig /renew or not.
The problem you must be trying to address is
Why your network connection is breaking after sometime
and not
How to repair your network connection every now and then
because if you are able to identify the root cause for first problem then you are done.
f 'r sng Wndws r bv, cn tr ths:
fcnfg | grp -c "P ddrss"
Ths wll gv th nmbr f mtchng P drsss - n cs r cnnctn s dwn, 'll hv fwr thn nrmll.
'll nd grp fr ths (s t's nt prt f Wndws), bt t cn b btnd frm ths RL: nxtls.srcfrg.nt

Resources