May 21, 2024, 04:58:47 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


shell_com example & system restore point

Started by Andy, January 06, 2011, 07:18:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Just wondered is there anyway to amend the shell_com example to include a keyboard shortcut for the desktop icon ?

i.e. Ctrl + Alt + K for example

I was also wondering how you could create a windows restore point.

I can do both of these with vb scripts but the idea is to do away with these and just use ebasic for all functions.

Currently i'm useing the free version of ebasic but will be purchasing the new version probably within 3 months.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

Hi Andy,

shell_link->SetHotkey(ASC("K") | ((HOTKEYF_ALT|HOTKEYF_CONTROL)<<8))
QuoteThe virtual key code is in the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a combination of the following values.
HOTKEYF_ALT - ALT key

HOTKEYF_CONTROL - CTRL key

HOTKEYF_EXT - Extended key

HOTKEYF_SHIFT - SHIFT key

Creating a restore point:
$include "windowssdk.inc"
$include "SrRestorePtApi.inc"

sub CreateRP(string Description),DWORD

' returns the number xxx in \System Volume Information\_restore{machine_guid}\RPxxx
DWORD seq = 0
RESTOREPOINTINFO rpi
STATEMGRSTATUS   sms

rpi.dwEventType      = BEGIN_SYSTEM_CHANGE ' APPLICATION_INSTALL APPLICATION_UNINSTALL DEVICE_DRIVER_INSTALL CANCELLED_OPERATION 
rpi.dwRestorePtType  = MODIFY_SETTINGS
rpi.llSequenceNumber = 0q ' put here an unique value

lstrcpyn(rpi.szDescription, Description, MAX_DESC)
rpi.szDescription[MAX_DESC-1] = 0

if (!SRSetRestorePoint(&rpi, &sms))

if (sms.nStatus = ERROR_SERVICE_DISABLED)

'ask("Would you like to start the service?")
'return on cancel
'EnableSystemRestore()
'SRSetRestorePoint(&rpi, &sms)
'return on failure
else
'show error
ShowSrError(sms)
return 0
endif
endif

' do your file/registry changes here, if any

seq                  = sms.llSequenceNumber
rpi.llSequenceNumber = sms.llSequenceNumber
rpi.dwEventType      = END_SYSTEM_CHANGE

if (!SRSetRestorePoint(&rpi, &sms))

'Failed to close restore point seq
ShowSrError(sms)
SRRemoveRestorePoint(seq)
seq = 0
endif

if (seq)
'created restore point seq, Description
endif

return seq
endsub


sub ShowSrError(STATEMGRSTATUS sms)

select (sms.nStatus)
case ERROR_BAD_ENVIRONMENT  :print "The function was called in safe mode"
case ERROR_DISK_FULL        :print "System Restore is in standby mode because disk space is low"
case ERROR_INTERNAL_ERROR   :print "An internal error occurred"
case ERROR_SERVICE_DISABLED :print "System Restore is disabled"
case ERROR_TIMEOUT          :print "The call timed out due to a wait on a mutex for setting restore points"
default                     :print "error ", sms.nStatus
endselect
endsub

Andy

Hi Sapero,

Thank you so much for replying, as always the hero !

Well, I've got the hot keys working with the shortcut - Thanks!

But i am having problems with the restore point code, there are two things -

1. I have to alter the code from

   if (!SRSetRestorePoint(&rpi, &sms))  to    if (SRSetRestorePoint(&rpi, &sms)) to avoid errors

2. Also, I'm sure i am missing something simple here, in the code before the first SUB routine do I need to call it and pass some parameters
e.g.

   CreateRP("My restore point"),200
   END

Because the code simply runs but no restore point is created (and system restore is already turned on).

I'm on e.b. version 1.62

Thanks,
Andy.


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

Andy, this is a function and you need to execute it manually with a string argument, but without ",200".

The '!' operator you removed needs to be there, but its form may be changed to comparision with zero:
"If !x" is the same as "if x=0".

if (0=SRSetRestorePoint(&rpi, &sms))

Andy

Thanks sapero !

That works great, thank you.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Hi sapero,

I just have one final question in your code you have the line

EnableSystemRestore()

This of course will turn on system restore if it's off, but how do you do it, you're calling a sub routine or function I think.

Do you have an example of this, the rest of the code works great.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

January 08, 2011, 07:32:13 AM #6 Last Edit: January 08, 2011, 07:34:08 AM by sapero
Hi Andy, this is a cut and paste from my old program (remove printf in your final version):
$include "windowssdk.inc"
$include "wbemidl.inc"
$include "stdio.inc" ' printf, console application1

' begin example
EnableSystemRestore()
end
' end example

sub EnableSystemRestore(),BOOL

BOOL success = FALSE

IWbemLocator pLoc      = NULL
IWbemServices pSvc     = NULL
IWbemClassObject pClass= NULL
IWbemClassObject pInParamsDefinition = NULL
IWbemClassObject pClassInstance = NULL
IWbemClassObject pOutParams = NULL


BSTR bstrString = NULL
BSTR bstrMethod = NULL
BSTR bstrClass  = NULL

CoInitializeEx(0, COINIT_MULTITHREADED)
CoInitializeSecurity(NULL, -1,NULL,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL)

int a
for a=0 to 0

if (CoCreateInstance(_CLSID_WbemLocator,0, CLSCTX_INPROC_SERVER, _IID_IWbemLocator, &pLoc))
printf("Failed to connect to WMI object IWbemLocator\n")
breakfor
endif
bstrString = SysAllocString(L"ROOT\Default")
if (pLoc->ConnectServer(bstrString,NULL,NULL,0,NULL,0,0,&pSvc))
printf("Failed to open WMI namespace %s\n", "ROOT\Default")
breakfor
endif
CoSetProxyBlanket(pSvc,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL,RPC_C_AUTHN_LEVEL_CALL,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE)

bstrClass = SysAllocString(L"SystemRestore")
if (pSvc->GetObject(bstrClass, 0, NULL, &pClass, NULL))
printf("Failed to open WMI object %S\n", bstrClass)
breakfor
endif
bstrMethod = SysAllocString(L"Enable")
if (pClass->GetMethod(bstrMethod, 0, &pInParamsDefinition, NULL))
printf("%s::GetMethod('%S') Failed\n", "IWbemClassObject", bstrMethod)
breakfor
endif
if (pInParamsDefinition->SpawnInstance(0, &pClassInstance))
printf("%s::SpawnInstance Failed\n", "IWbemClassObject")
breakfor
endif
' Create the values for the in parameters
VARIANT varCommand
varCommand.vt = wbemCimtypeString
varCommand.bstrVal = SysAllocString(L"")

if (pClassInstance->_Put(L"Drive", 0, &varCommand, 0))
printf("%s::Put('%s') Failed\n", "IWbemClassObject", "Drive")
SysFreeString(varCommand.bstrVal)
breakfor
endif
SysFreeString(varCommand.bstrVal)

DWORD hr = pSvc->ExecMethod(bstrClass, bstrMethod, 0, NULL, pClassInstance, &pOutParams, NULL)
if (hr&0x80000000)
printf("%s::ExecMethod('%S') Failed: 0x%X\n", "IWbemServices", bstrMethod, hr)
breakfor
endif
VARIANT varReturnValue
SysFreeString(bstrString)
bstrString = SysAllocString(L"ReturnValue")
if (pOutParams->_Get(bstrString, 0, &varReturnValue, NULL, 0))
printf("%s::Get('%S') Failed\n", "IWbemClassObject", bstrString)
breakfor
endif
' printf("vt     = %d\n", varReturnValue.vt)
' printf("intVal = %d\n", varReturnValue.intVal)

success = (varReturnValue.intVal = 0)
if (!success and (varReturnValue.intVal <> ERROR_SERVICE_ALREADY_RUNNING))
printf(" - EnableSystemRestore returned error %d\n", varReturnValue.intVal)
else
puts("success")
endif
next a
if (bstrString) then SysFreeString(bstrString)
if (bstrMethod) then SysFreeString(bstrMethod)
if (bstrClass) then SysFreeString(bstrClass)

if (pOutParams) then pOutParams->Release()
if (pClassInstance) then pClassInstance->Release()
if (pInParamsDefinition) then pInParamsDefinition->Release()
if (pClass) then pClass->Release()
if (pSvc) then pSvc->Release()
if (pLoc) then pLoc->Release()
CoUninitialize()
return success
endsub

Andy

Thanks sapero - will give it a go - once again many thanks.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.