wmic delete startup item - wmic

I want to delete an entry with wmic but i always get an error, i saw DELETE command is a valid verb of STARTUP. what i am doing wrong?
thnx
wmic:root\cli>/node:'pc-test' startup where name="TwonkyServer" DELETE
Delete '\\pc-test\ROOT\CIMV2:Win32_StartupCommand.Command="C:\\PROGRA~1\\Twonky\\TWONKY~1\\TWONKY~4.EXE ",Location="Common Startup",Name="TwonkyServer",User="Public"' (Y/N/?)? y
Deleting instance \\pc-test\ROOT\CIMV2:Win32_StartupCommand.Command="C:\\PROGRA~1\\Twonky\\TWONKY~1\\TWONKY~4.EXE ",Location="Common Startup",Name="TwonkyServer",User="Public"
ERROR:
Description = Provider is not capable of the attempted operation

I don't know if you can achieve it through WMI console, but through VBS try providing a priviliged moniker string in reference to the system:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa389292(v=vs.85).aspx

You Can Get The Entry By This Command:
wmic startup get Location | findstr /B /C:"TwonkyServer"
Then Delete It From Registry
Reg delete [{/v ValueName | /ve | /va}] [/f]
More Help At Reg Delete At:
https://technet.microsoft.com/en-us/library/cc742145.aspx

Related

Use variable in batch file multiple times

I'm trying to compile a batch file to get the userID of the current user, then use the output to delete a certain registry key.
I found this to get the SID of the current logged in user:
wmic useraccount where name='%username%' get sid
This worked perfectly and gave me:
SID
S-1-5-21-XXXXX-XXXXX-XXXX-XXX
Now I would like to use the S-1-5-21.... etc. To delete a certain registry key for the current logged in user, so the S-1-5-21 etc. How can I do that? Or is there an easier way, being able to determine current SID and delete a key consequently?
thank you!
Assuming you want to delete the registry key...
HKEY_USERS\[SID-OF-USER]\test
...this script should cut it:
#ECHO OFF
SET USERNAME=SomeUserName
:: retrieve user's SID, store in file. NOTE: a user can have more than 1 SID.
wmic useraccount where name='%USERNAME%' get sid | FINDSTR "^S-" > tmp.txt
:: load result into variable. NOTE: this will load the first line only.
SET /P SID_=<tmp.txt
:: remove spaces which turned out to be appended at the end.
SET SID=%SID_: =%
:: delete key in the registry (will probably required elevated privileges)
:: the /F causes reg.exe not to ask for confirmation
REG DELETE "HKEY_USERS\%SID%\test" /F
:: cleanup
DEL tmp.txt
I'm not aware of an easier way to "determine current SID and delete a key".
Try this:
#echo off
wmic useraccount where name='%username%' get sid > temp.txt &more temp.txt > temp2.txt &del temp.txt
for /F "tokens=*" %%A in (temp2.txt) do set "userID=%%A"
del temp2.txt
echo %userID%
pause
You can use the %userID% variable after this code.
Note that you need to use the more because of the way wmic parses it's output

How do I copy a directory?

I want to copy one directory from one location to another but while copying I am getting an error message:
"Could not complete operation on some files and directories. See the Data property of the exception for more details." i don't know what is the problem
I tried:
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(FolderBrowserDialog1.SelectedPath, System.IO.Path.Combine(curDir, filename.Name))
and
My.Computer.FileSystem.CopyDirectory(FolderBrowserDialog1.SelectedPath, System.IO.Path.Combine(curDir, filename.Name))
But I am still getting same message .
Any pointers on how to get around this?
Thanks.
You could try using
Process.StartInfo.Filename = "xcopy"
Process.StartInfo.Arguments = String.Format("{0} {1} {2}", sourcedir, destdir, xcopyflags)
Process.Start()
If you're not sure of the flags or usage you can open a command prompt and type
xcopy /?

Cannot delete a printer queue on OpenVMS

Im trying to delete a printer queue but I always receive the message:
$> delete/que myprinter
%DELETE-E-NOTDELETED, error deleting MYPRINTER
-JBC-E-REFERENCED, existing references prevent deletion
$> sh que/all/full myprinter
Server queue MYPRINTER, stopped, on MYSERVER::, mounted form A4_LINEP_LS (stock=DEFAULT)
/BASE_PRIORITY=4 /DEFAULT=(FEED,FORM=DEFAULT) /OWNER=[SYSTEM] /PROCESSOR=TCPIP$LPD_SMB /PROTECTION=(S:M,O:D,G:R,W:S) /RETAIN
I try the "user action" suggested in this cases - delete all entryes and references to the queue and apparently there is no more references since the $ show que/full/all command shows nothing.
Anyway, ther must have a hiden reference, but where?
Can you help me?
From the OpenVMS System Manager's Manual: the queue you are attempting to delete might be named as a target for a generic queue.... To check for such a target queue do a $ pipe show queue/generic/full |search sys$pipe generic. If your queue shows you want to remove it from the generic queue.

hide error messages in dcl script

I have a test script I'm running that generates some errors,shown below, I expect these errors. Is there anyway I can prevent them from showing on the screen however? I use the
$ write sys$output
to display if there is an expected error.
I tried to use
$ DEFINE SYS$ERROR ERROR.LOG
but this then changed my entire error output log to this, if this is the correct way to handle it can I unset this at the end of my script somehow?
[error example]
%DCL-E-OPENIN, error opening TEST$DISK:[AAA]NOTTHERE.TXT; as input
-RMS-E-FNF, file not found
%DCL-E-OPENIN, error opening TEST$DISK:[AAA]NOTTHERE.TXT; as input
-RMS-E-FNF, file not found
%DCL-W-UNDFIL, file has not been opened by DCL - check logical name
DEFINE/USER creates a logical name that disappears when the next image exits.
So if you use that just before a command just to protect that command, then fine.
Otherwise I would prefer SET MESSAGE to control the output.
And of course yoy want to grab $STATUS and verify it after the command for success or for the expected error, reporting any unexpected error.
Better still... if you expect certain error conditions to occur,
then why not test for them?
For example:
$ file = F$SEARCH("TEST$DISK:[AAA]NOTTHERE.TXT")
$ IF file.NES."" THEN TYPE 'file'
Cheers,
Hein
To suppress Error message inside a script. try this command
$ DEFINE/USER SYS$ERROR NL:
NL: is a null device, so you don`t see any error messages displayed on your terminal.
good luck
This works interactively and in batch.
$ SET MESSAGE /NOTEXT /NOSEV /NOFAC /NOID
$ <DCL_Command>
$ SET MESSAGE /TEXT /SEV /FAC/ ID

how to get the information of system log of taskscheduler under the command line with WMIC?

I need to know whether the taskscheduler has run successfully. I found difficult to get a return value by the wmic command, because they aren't included in the system, security, application hardwareevents and so on logfile. Following is my attempts:
wmic ntevent "eventcode=140" get message /value
The above code returns the message: "no instance(s) availalbe."
As I don't know which kind of logfile includes the log records of taskschedule, I select them by the eventcode.
wmic ntevent where "logfile='system' and eventcode='140'" get message /vule
No matter, logfile='appliaction' or logfile='security', at the end I can't get the result I want.
What i need to point out is the log records are allocated in Microsoft-Windows-TaskScheduler/Operational in graphical interfaces.
Unfortunately, wmic can only be used on classic logs. List them by
wmic NTEventlog get LogfileName or by powershell Get-EventLog -AsString -List:
Application
HardwareEvents
Internet Explorer
Key Management Service
PreEmptive
Security
System
TuneUp
Windows PowerShell
Switch to wevtutil: wevtutil enum-logs enumerates the available logs and
wevtutil qe Microsoft-Windows-TaskScheduler/Operational /q:"*[System[Provider[#Name='Microsoft-Windows-TaskScheduler'] and (EventID=140)]]" /uni:false /f:text
command could be a starting point for you. Pretty weird syntax and result hard do parse. Moreover:
The primary focus of WEVTUTIL is the configuration and setup of
event logs, to retrieve event log data the PowerShell cmdlet
Get-WinEvent is easier to use and more flexible:
Switch to powershell: (Get-WinEvent -ListLog *).LogName enumerates the available logs and one can simply filter and format result from next command:
Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational
For instance, to format the result in list view to see all properties:
Get-WinEvent -LogName Microsoft-Windows-TaskScheduler/Operational | Format-List *
Read more in Powershell and the Applications and Services Logs.