Jump to content

Stuck in _WinAPI_SystemParametersInfo


 Share

Recommended Posts

In an effort to try to help another member here in the forum, i gained interest in this matter and head in for the dll calls and the api's,

This user wants to set the icon size, same as, say, in desktop pressing right mouse button -> view -> and selecting the size, Small Medium or Large Icons.

I thought i start with retrieving the current size first. In order to do that the api is: SPI_GETICONMETRICS

So my search lead me to IconMetrics, a structure part of SystemParametersInfo.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648054(v=vs.85).aspx

Now, this is what i tried that led to the best results.. 4 zeroes.

Got an issue that i can think may be stopping this from working, im not including "LOGFONT lfFont" in the DllStructCreate. (do i need to include all and every parameter?)

And the reason i didn't include it is because i don't know the type, it gives out an error, so it seems after more searching, sorry "im noob" that this is yet another scructure, that includes the sizes of the font and everything about the font.

Can anyone point me in the right direction?

#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>
;LOGFONT lfFont
Local Const $tagLOGFONT = DllStructCreate('long lfHeight;long lfWidth;long lfEscapement;long lfOrientation;long lfWeight;byte lfItalic;byte lfUnderline;byte lfStrikeOut;byte lfCharSet;byte lfOutPrecision;byte lfClipPrecision;byte lfQuality;byte lfPitchAndFamily;char lfFaceName;');Recreated but dont know what to do with it.
Local Const $ICONMETRICS = DllStructCreate('uint cbSize;int iHorzSpacing;int iVertSpacing;int iTitleWrap')
If @error Then
    MsgBox(64, 'error', @error)
EndIf
Local $Params = _WinAPI_SystemParametersInfo($SPI_GETICONMETRICS, 'BOOLEAN', $ICONMETRICS)
If not @error Then
ConsoleWrite(DllStructGetData($ICONMETRICS, 'cbSize')&DllStructGetData($ICONMETRICS, 'iHorzSpacing')&DllStructGetData($ICONMETRICS, 'iVertSpacing')&DllStructGetData($ICONMETRICS, 'iTitleWrap')&@CRLF)
Else
    MsgBox(64, 'error', @error)
EndIf
Spoiler

Refences:


typedef struct tagICONMETRICS {
  UINT    cbSize;
  int     iHorzSpacing;
  int     iVertSpacing;
  int     iTitleWrap;
  LOGFONT lfFont;
} ICONMETRICS, *PICONMETRICS, *LPICONMETRICS;

BOOL WINAPI SystemParametersInfo(
  _In_    UINT  uiAction,
  _In_    UINT  uiParam,
  _Inout_ PVOID pvParam,
  _In_    UINT  fWinIni
);

typedef struct tagLOGFONT {
  LONG  lfHeight;
  LONG  lfWidth;
  LONG  lfEscapement;
  LONG  lfOrientation;
  LONG  lfWeight;
  BYTE  lfItalic;
  BYTE  lfUnderline;
  BYTE  lfStrikeOut;
  BYTE  lfCharSet;
  BYTE  lfOutPrecision;
  BYTE  lfClipPrecision;
  BYTE  lfQuality;
  BYTE  lfPitchAndFamily;
  TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;

 

 

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

hello. I think you need to do something like this:

Global Const $sTagLOGFONT = 'long lfHeight;long lfWidth;long lfEscapement;long lfOrientation;long lfWeight;byte lfItalic;byte lfUnderline;byte lfStrikeOut;byte lfCharSet;byte lfOutPrecision;byte lfClipPrecision;byte lfQuality;byte lfPitchAndFamily;char lfFaceName;'
Global Const $sTagICONMETRICS='uint cbSize;int iHorzSpacing;int iVertSpacing;int iTitleWrap;' & $sTagLOGFONT
Local  $tICONMETRICS = DllStructCreate($sTagICONMETRICS)

EDIT:

lfFaceName need to be lfFaceName[32]

Saludos

Edited by Danyfirex
Edit
Link to comment
Share on other sites

Hi, thanks for answer, i see, so it's a continuation of the struct, but still not working. What i tried with your changes.

#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>
Global Const $sTagLOGFONT = 'long lfHeight;long lfWidth;long lfEscapement;long lfOrientation;long lfWeight;byte lfItalic;byte lfUnderline;byte lfStrikeOut;byte lfCharSet;byte lfOutPrecision;byte lfClipPrecision;byte lfQuality;byte lfPitchAndFamily;char lfFaceName[32];'
Global Const $sTagICONMETRICS='uint cbSize;int iHorzSpacing;int iVertSpacing;int iTitleWrap;' & $sTagLOGFONT
Local  $tICONMETRICS = DllStructCreate($sTagICONMETRICS)
If @error Then
    MsgBox(64, '@error', @error)
EndIf
Local $Params = _WinAPI_SystemParametersInfo($SPI_GETICONMETRICS, 'BOOLEAN', $tICONMETRICS)
If not @error Then
ConsoleWrite(DllStructGetData($tICONMETRICS, 'cbSize')&DllStructGetData($tICONMETRICS, 'iHorzSpacing')&DllStructGetData($tICONMETRICS, 'iVertSpacing')&DllStructGetData($tICONMETRICS, 'iTitleWrap')&@CRLF)
Else
    MsgBox(64, '@error', @error)
EndIf

Still 4 zero and no errors.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You  don't have to chek for @error because the function returns 0 or 1 but doesn't set @error

In your case, check the $Params value.

The function uses Unicode, so the $sTagLOGFONT must use wchar instead of char

Also, you have to set the size of the $tICONMETRICS structure in cbSize and in the $iParam param of _WinAPI_SystemParametersInfo

 

Here is a working example :

 

#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>


Global Const $sTagLOGFONT = 'long lfHeight;long lfWidth;long lfEscapement;long lfOrientation;long lfWeight;byte lfItalic;byte lfUnderline;byte lfStrikeOut;byte lfCharSet;byte lfOutPrecision;byte lfClipPrecision;byte lfQuality;byte lfPitchAndFamily;wchar lfFaceName[32];'
Global Const $sTagICONMETRICS='uint cbSize;int iHorzSpacing;int iVertSpacing;int iTitleWrap;' & $sTagLOGFONT
Local  $tICONMETRICS = DllStructCreate($sTagICONMETRICS)

Local $iSize = DllStructGetSize($tICONMETRICS)


DllStructSetData($tICONMETRICS, "cbSize", $iSize)


Local $iRet = _WInAPI_SystemParametersInfo($SPI_GETICONMETRICS, $iSize, $tICONMETRICS)


If $iRet Then
    ConsoleWrite(DllStructGetData($tICONMETRICS, 'cbSize') & @TAB & DllStructGetData($tICONMETRICS, 'iHorzSpacing') & @TAB & DllStructGetData($tICONMETRICS, 'iVertSpacing') & @TAB & DllStructGetData($tICONMETRICS, 'iTitleWrap')&@CRLF)
Else
    MsgBox(0, "Error", _WinAPI_GetLastErrorMessage() )

EndIf

Edit : @Danyfirex, I was trying to make the structure by myself, but I didn't manage to get it work. I thought I had to use a ptr the LOGFONT structure...

 

Edited by jguinch
Link to comment
Share on other sites

Ah nice, learned a lot.

Thanks. Will play some more with these.

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You know, $SPI_SETICONMETRICS won't allow you answer to the user's question (change the size of icons), but only change the size of the desktop icons, but only the font of the icons...

Link to comment
Share on other sites

Yeah, i noticed that later on, but doesn't matter because he's got his question solved, and i learned a bit more on this.

Now im stuck on another thing im trying to do, just for the learning process.

There's this GetSystemTime call, and it works, now im trying to set system time, but i can't.

$SYSTEMTIME=DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort wMinute;ushort wSecond;ushort wMilliseconds")
DllCall("Kernel32.dll","none","GetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))
ConsoleWrite("Current time: "&DllStructGetData($SYSTEMTIME,"wHour")&":"&DllStructGetData($SYSTEMTIME,"wMinute")&@CRLF)

$SYSTEMTIME=DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort $wMinute;ushort wSecond;ushort wMilliseconds")
$Time = DllCall("Kernel32.dll","BOOL","SetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))
MsgBox(0,"Min",DllStructSetData($SYSTEMTIME,"wMinute", 11))

Im thinking i should set the minutes value, before the call, but not sure how.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

- You have a syntax error in the second DllStructCreate ($wMinute => wMinute)
- You must have sufficient privileges to change the system date
- If you want to change the date/hour, you have to set the value in the structure before calling SetSystemTime

Edited by jguinch
Link to comment
Share on other sites

$SYSTEMTIME=DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort wMinute;ushort wSecond;ushort wMilliseconds")
DllStructSetData($SYSTEMTIME,'wMinute', 11)
$Time = DllCall("Kernel32.dll","BOOL","SetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))

setting wminute to 11 didnt work as i thought it would

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You have to set each value, not only wMinute.

You have two choices :
 - create a structure and set each value (it's what you did, with DllStructCreate + DllStructSetData)
 - call GetSystemTime first to get all value in structure,  change wMinute (you know how) in this structure and then call SetSystemTime

If it's not clear enough, I will post the code,

Edited by jguinch
Link to comment
Share on other sites

Now, it's time for me to go to bed.
So here is a solution, I hope it will help you :

Spoiler
#RequireAdmin

#Include <WinAPI.au3> ; Only for _WinAPI_GetLastErrorMessage


Local $tSYSTEMTIME = DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort wMinute;ushort wSecond;ushort wMilliseconds")
DllCall("Kernel32.dll","none","GetSystemTime","ptr",DllStructGetPtr($tSYSTEMTIME)) ; gets the current time values in the structure (not needed if you want to set each value manually)

; Set each value that you want to change
DllStructSetData($tSYSTEMTIME, "wMinute", 45) ; sets the minutes to 45 in the structure
; DllStructSetData($tSYSTEMTIME, "wHour", 2) ; sets the hour to 2 in the structure

Local $aTime = DllCall("Kernel32.dll","BOOL","SetSystemTime","ptr",DllStructGetPtr($tSYSTEMTIME)) ; now, call SetSystemTime using the modified structure

If @error Or Not $aTime[0] Then ConsoleWrite(_WinAPI_GetLastErrorMessage() ) ; here you can get the error message

 

 

Edited by jguinch
Link to comment
Share on other sites

Many thanks, as soon as you said i needed to set all values, i went ahead and came up with this.

I understood both of the options you mentioned. Thank you, starting to get a little of how this works.

$SYSTEMTIME=DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort wMinute;ushort wSecond;ushort wMilliseconds")
DllCall("Kernel32.dll","none","GetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))
$Year = DllStructGetData($SYSTEMTIME,"wYear")
$Month = DllStructGetData($SYSTEMTIME,"wMonth")
$WDay = DllStructGetData($SYSTEMTIME,"wDayOfWeek")
$Day = DllStructGetData($SYSTEMTIME,"wDay")
$Hour = DllStructGetData($SYSTEMTIME,"wHour")
$Min = DllStructGetData($SYSTEMTIME,"wMinute")
$Sec = DllStructGetData($SYSTEMTIME,"wSecond")
$MSec = DllStructGetData($SYSTEMTIME,"wMilliseconds")


;$SYSTEMTIME=DllStructCreate("ushort wYear;ushort wMonth;ushort wDayOfWeek;ushort wDay;ushort wHour;ushort wMinute;ushort wSecond;ushort wMilliseconds")
DllStructSetData($SYSTEMTIME,'wYear', $Year)
DllStructSetData($SYSTEMTIME,'wMonth', $Month)
DllStructSetData($SYSTEMTIME,'wDayOfWeek', $WDay)
DllStructSetData($SYSTEMTIME,'wDay', $Day)
DllStructSetData($SYSTEMTIME,'wHour', $Hour)
DllStructSetData($SYSTEMTIME,'wMinute', 47);$Min Set to 47
DllStructSetData($SYSTEMTIME,'wSecond', $Sec)
DllStructSetData($SYSTEMTIME,'wMilliseconds', $MSec)
$Time = DllCall("Kernel32.dll","BOOL","SetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))

MsgBox(64, '', 'Set back') ;nice! it changed, now lets put the previous value back in.
DllStructSetData($SYSTEMTIME,'wYear', $Year)
DllStructSetData($SYSTEMTIME,'wMonth', $Month)
DllStructSetData($SYSTEMTIME,'wDayOfWeek', $WDay)
DllStructSetData($SYSTEMTIME,'wDay', $Day)
DllStructSetData($SYSTEMTIME,'wHour', $Hour)
DllStructSetData($SYSTEMTIME,'wMinute', $Min);write original value, because this is just a test.
DllStructSetData($SYSTEMTIME,'wSecond', $Sec)
DllStructSetData($SYSTEMTIME,'wMilliseconds', $MSec)
$Time = DllCall("Kernel32.dll","BOOL","SetSystemTime","ptr",DllStructGetPtr($SYSTEMTIME))

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...