Hello,
I have a code with Windows but it runs as administrator.
Regards,
Bernard.
// begin code.
/* Certicates console to csv file.
This code is a basic sample for tests.
Obtenir les certificats de l'ordinateur vers fichier.csv.
Ce code est disponible dans l'état sans aucune garantie.
Le risques de l'utilisation de ce code est sous la responsabilité de l'utilisateur,
que ce code soit dans l'état ou avec des modifications qui sont autorisées.
Ce programme crée un fichier exécutable en VB script qui va lui-même
créer un fichier.csv que l'on peut ouvrir avec Excel ou Open Office.
Certaines commandes VB Script ne fonctionnent pas avec dBase.
On fabrique le fichier.csv en VB Script et on le récupère en dBase.
Une question est posée si on veut lancer le programme VB script
car il faut lancer le programme en tant qu'Administrateur.
Compile with -lhbwin
*/
// Change this parameters.
#define VARIABLE_SEPARATEUR " ; " // Columns separator.
#define MAX_COLONNES "10" // Maximum number of columns to retrieve.
#define FILE_VBS hb_dirbase() + "_Result.vbs" // VBScript program.
#define FILE_CSV hb_dirbase() + "_Result.csv" // CSV output file.
procedure main
local cStringe := ""
request HB_CODEPAGE_FRWIN
hb_cdpSelect( 'FRWIN' )
setmode( 25, 80 )
ferase( FILE_VBS )
ferase( FILE_CSV )
// Create the VBS file.
cStringe += "'Get the computer certificates in an Excel file." + hb_eol()
cStringe += hb_eol()
cStringe += "'This code is available in the state without any warranty." + hb_eol()
cStringe += "'The risk of using this code is the responsibility of the user," + hb_eol()
cStringe += "'Whether that code is in the state or with changes that are allowed." + hb_eol()
cStringe += hb_eol()
cStringe += "'You can change the folder name below if you want." + hb_eol()
cStringe += "'Create a shortcut -> wscript.exe " + '"' + FILE_VBS + '"' + hb_eol()
cStringe += "'and run with Administritor rights." + hb_eol()
cStringe += hb_eol()
cStringe += 'Option Explicit' + hb_eol()
cStringe += 'Dim oTrans' + hb_eol()
cStringe += 'Set oTrans = CreateObject( "Scripting.FileSystemObject" )' + hb_eol()
cStringe += 'Dim oTransF' + hb_eol()
cStringe += hb_eol()
cStringe += "'You can change the folder name below if you want." + hb_eol()
cStringe += 'Set oTransF = oTrans.OpenTextFile( "' + FILE_CSV + '", 2, True )' + hb_eol()
cStringe += 'Dim objMMC' + hb_eol()
cStringe += 'Set objMMC = CreateObject( "MMC20.Application" )' + hb_eol()
cStringe += 'objMMC.Load( "certmgr.msc" )' + hb_eol()
cStringe += 'Dim objDoc' + hb_eol()
cStringe += 'Set objDoc = objMMC.Document' + hb_eol()
cStringe += 'Dim objSN' + hb_eol()
cStringe += 'Set objSN = objDoc.ScopeNamespace' + hb_eol()
cStringe += 'Dim objRoot' + hb_eol()
cStringe += 'Set objRoot = objDoc.RootNode' + hb_eol()
cStringe += 'Dim objEvtVwrNode' + hb_eol()
cStringe += 'Set objEvtVwrNode = objSN.GetChild( objRoot )' + hb_eol()
cStringe += 'objSN.Expand( objEvtVwrNode )' + hb_eol()
cStringe += 'Dim objView' + hb_eol()
cStringe += 'Set objView = objDoc.ActiveView' + hb_eol()
cStringe += 'On Error Resume Next' + hb_eol()
cStringe += 'Dim objNode' + hb_eol()
cStringe += 'Set objNode = Nothing' + hb_eol()
cStringe += 'Set objNode = objSN.GetChild( objEvtVwrNode )' + hb_eol()
cStringe += 'If ( objNode Is Nothing ) then' + hb_eol()
cStringe += ' oTransF.writeline "** Error : objNode Is Nothing, quit."' + hb_eol()
cStringe += ' oTransF.Close' + hb_eol()
cStringe += ' Wscript.quit' + hb_eol()
cStringe += 'End If' + hb_eol()
cStringe += 'Do Until ( objNode Is Nothing )' + hb_eol()
cStringe += ' objSN.Expand( objNode )' + hb_eol()
cStringe += ' objView.ActiveScopeNode = objNode' + hb_eol()
cStringe += ' Dim cFolder' + hb_eol()
cStringe += ' Set cFolder = Nothing' + hb_eol()
cStringe += ' Set cFolder = objSN.GetChild( objNode )' + hb_eol()
cStringe += ' Do Until ( cFolder Is Nothing )' + hb_eol()
cStringe += ' objSN.Expand( cFolder )' + hb_eol()
cStringe += ' objView.ActiveScopeNode = cFolder' + hb_eol()
cStringe += ' Dim objList' + hb_eol()
cStringe += ' Set objList = objView.ListItems' + hb_eol()
cStringe += ' Dim objItem' + hb_eol()
cStringe += ' For Each objItem In objList' + hb_eol()
cStringe += ' Dim str' + hb_eol()
cStringe += ' str = objView.CellContents( objItem, 1 )' + hb_eol()
cStringe += ' If (str <> "Error") Then' + hb_eol()
cStringe += ' Dim cLine' + hb_eol()
cStringe += ' Dim I' + hb_eol()
cStringe += ' cLine = objNode.Name + "' + VARIABLE_SEPARATEUR + '" + cFolder.Name' + hb_eol()
cStringe += ' For I = 1 To ' + MAX_COLONNES + hb_eol()
cStringe += ' cLine = cLine + "' + VARIABLE_SEPARATEUR + '" + objView.CellContents( objItem, I )' + hb_eol()
cStringe += ' Next' + hb_eol()
cStringe += ' oTransF.writeline cLine' + hb_eol()
cStringe += ' End If' + hb_eol()
cStringe += ' Next' + hb_eol()
cStringe += ' Dim objSib2' + hb_eol()
cStringe += ' Set objSib2 = Nothing' + hb_eol()
cStringe += ' Set objSib2 = objSN.GetNext( cFolder )' + hb_eol()
cStringe += ' Set cFolder = objSib2' + hb_eol()
cStringe += ' Loop' + hb_eol()
cStringe += ' Dim objSib' + hb_eol()
cStringe += ' Set objSib = Nothing' + hb_eol()
cStringe += ' Set objSib = objSN.GetNext( objNode )' + hb_eol()
cStringe += ' Set objNode = objSib' + hb_eol()
cStringe += 'Loop' + hb_eol()
cStringe += 'oTransF.Close' + hb_eol()
cStringe += 'Wscript.quit'
hb_memowrit( FILE_VBS, cStringe )
wapi_ShellExecute( 0 ;
, "runas" ; // Open with the Administrator rights.
, "wscript.exe" ; // Appli to open.
, FILE_VBS ; // Parameters.
, SET( "DIRECTORY" ) ; // Folder.
, 1 ) // Display mode.
return
// End code.