Anonymní profil s3n0 – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil s3n0 – Programujte.comAnonymní profil s3n0 – Programujte.com

 

Příspěvky odeslané z IP adresy 178.253.164.–

Příkazový řádek › VBS script pre zistenie stav…
6. 6. 2014   #190803

#4 s3n0
este doplnim mnou mierne poupraveny spominany C++ kod demonstrujuci zapnutie a vypnutie monitoru ako aj nacitania "power saving" aktualneho rezimu monitoru... jedna sa tu o upraveny koniec kodu resp. jedna sa o hlavny vykonavaci program - main{} , kde pridavam Sleep-prikazy, nakolko nejaky cas trva, kym sa vypne monitor a zaroven "nabehne" idle rezim stav... takze su tam tie 3 sekundy vyckavacej doby, aby sa aktivoval IDLE rezim monitoru, po jeho samotnom vypnuti a aby ukazala hodnota cislo 4 platna uz pre uspany monitor

// monitor_info.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
 
#ifdef _MSC_VER
#pragma comment(lib, "Setupapi.lib")
#endif
 
#include <list>
#include <vector>
#include <string>
using namespace std;
 
// my StlPort configured w/o iostreams at the moment
#include <stdio.h>
 
//------------------------------------------------------------------------------
 
struct DevData
{
    std::wstring Description;  // SPDRP_DEVICEDESC
    CM_POWER_DATA PowerData;   // SPDRP_DEVICE_POWER_DATA
 
    DevData()
    {
        PowerData.PD_Size = sizeof(PowerData);
    }//constructor
};//DevData
 
//------------------------------------------------------------------------------
 
bool GetDeviceRegString(HDEVINFO infoSet, SP_DEVINFO_DATA *pinfoData,
                        DWORD prop, wstring &val)
{
    DWORD req_sz = 0;
    BOOL res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                                 0, 0, 0, &req_sz);
    if (!res && (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
    {
        if (GetLastError() != ERROR_INVALID_DATA)
        {
            printf("SetupDiGetDeviceRegistryPropertyW() failed, le = &#37;u",
                   GetLastError());
        }//if
 
        return false;
    }//if
 
    vector<wchar_t> vec_buff; // in case we have to go to the heap
    wchar_t auto_buff[512];
 
    DWORD buff_sz;
    wchar_t *buff;
    if (req_sz > sizeof(auto_buff))
    {
        vec_buff.reserve(req_sz/2 + 2);
        buff = &vec_buff[0];
        buff_sz = req_sz;
    }//if
    else
    {
        buff = auto_buff;
        buff_sz = sizeof(auto_buff);
    }//else
 
    res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                            0, (PBYTE)buff, buff_sz, 0);
    if (!res)
    {
        DWORD le = GetLastError();
        if (le != ERROR_INVALID_DATA)
        {
            printf("SetupDiGetDeviceRegistryPropertyW(%d) "
                   "failed, le = %u",
                   prop, le);
            return false;
        }//if
 
        // return empty string on ERROR_INVALID_DATA
        val.erase(val.begin(), val.end());
        return true;
    }//else
 
    val.assign(buff, req_sz);
    return true;
}//GetDeviceRegString
 
//------------------------------------------------------------------------------
 
template <typename T>
bool GetDeviceRegData(HDEVINFO infoSet, SP_DEVINFO_DATA *pinfoData,
                        DWORD prop, T &val)
{
    SetLastError(0);
    BOOL res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                                 0, (PBYTE)&val,
                                                 sizeof(val), 0);
    DWORD le = GetLastError();
    if (!res || (le == ERROR_INVALID_DATA))
    {
        if (le != ERROR_INVALID_DATA)
            printf("GetDeviceRegData() failed, le = %u", le);
        return false;
    }//if
 
    return true;
}//GetDeviceRegData
 
//------------------------------------------------------------------------------
 
void ListDeviceClassData(const GUID *classGuid, std::list<DevData> &devList)
{
    devList.clear();
 
    const DWORD flags = DIGCF_PRESENT;
    HDEVINFO infoSet = SetupDiGetClassDevsW(classGuid, 0, 0, flags);
    if (infoSet == INVALID_HANDLE_VALUE)
    {
        printf("SetupDiGetClassDevs() failed, le = %u",
               GetLastError());
        return;
    }//if
 
    SP_DEVINFO_DATA infoData;
    infoData.cbSize = sizeof(SP_DEVINFO_DATA);
 
    DWORD n;
    for (n = 0; SetupDiEnumDeviceInfo(infoSet, n, &infoData); ++n)
    {
        DevData dd;
        if (GetDeviceRegString(infoSet, &infoData, SPDRP_DEVICEDESC,
                               dd.Description) &&
            GetDeviceRegData(infoSet, &infoData, SPDRP_DEVICE_POWER_DATA,
                             dd.PowerData))
        {
            devList.push_back(dd);
        }//if
    }//for
 
    if (GetLastError() != ERROR_NO_MORE_ITEMS)
    {
        printf("Last call to SetupDiEnumDeviceInfo(%d) failed, le = %u",
               n, GetLastError());
    }//if
 
    SetupDiDestroyDeviceInfoList(infoSet);
}//ListDeviceClassData
 
//------------------------------------------------------------------------------
 
void print_monitor_info()
{
    const GUID MonitorClassGuid =
        {0x4d36e96e, 0xe325, 0x11ce,
            {0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}};
     
    list<DevData> monitors;
    ListDeviceClassData(&MonitorClassGuid, monitors);
 
    printf("# Monitors = %d\n", monitors.size());
 
    list<DevData>::iterator it = monitors.begin(),
                            it_end = monitors.end();
    for (; it != it_end; ++it)
    {
        const char *off_msg = "";
 
        if (it->PowerData.PD_MostRecentPowerState > PowerDeviceD0)
            off_msg = ", *** Sleeping State ***";
 
        printf("[%ls]\n"
               "   PowerState = %d%s\n",
               it->Description.c_str(),
               it->PowerData.PD_MostRecentPowerState,
               off_msg);
    }//for
     
    putchar('\n');
}//print_monitor_info
 
//------------------------------------------------------------------------------
 
int main()
{
    printf("\n\n\n\n*** Current Status of Monitor(s) ***\n\n");
    print_monitor_info();
    Sleep(3000);

    printf("\n\n\n\n*** Turning OFF Monitor(s) ***\n\n");
    fflush(stdout);
    Sleep(500); // don't use mouse or keyboard
    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
    Sleep(3000);
	print_monitor_info();
    Sleep(3000);

    printf("\n\n\n\n*** Turning ON Monitor(s) ***\n\n");
    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
    Sleep(3000);    
	print_monitor_info();
    Sleep(3000);

    return 0;
}//main
 
//------------------------------------------------------------------------------

co sa tyka pouzitia v CMD scriptoch, tak samozrejme som si musel upravit main{} proceduru... a vyuzivam tam pridanu globalnu premennu int stav_napajania... fakt primitivizmus, ale nemam cas fakt uz na to hehe... nechcelo sa mi trapit sa s tym dalsie hodiny :D tak som to vyriesil naozaj velmi razne a jednoducho :D vid kod:

// monitor_info.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <setupapi.h>
 
#ifdef _MSC_VER
#pragma comment(lib, "Setupapi.lib")
#endif
 
#include <list>
#include <vector>
#include <string>
using namespace std;
 
// my StlPort configured w/o iostreams at the moment
#include <stdio.h>

int stav_napajania = 0;

//------------------------------------------------------------------------------
 
struct DevData
{
    std::wstring Description;  // SPDRP_DEVICEDESC
    CM_POWER_DATA PowerData;   // SPDRP_DEVICE_POWER_DATA
 
    DevData()
    {
        PowerData.PD_Size = sizeof(PowerData);
    }//constructor
};//DevData
 
//------------------------------------------------------------------------------
 
bool GetDeviceRegString(HDEVINFO infoSet, SP_DEVINFO_DATA *pinfoData,
                        DWORD prop, wstring &val)
{
    DWORD req_sz = 0;
    BOOL res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                                 0, 0, 0, &req_sz);
    if (!res && (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
    {
        if (GetLastError() != ERROR_INVALID_DATA)
        {
            printf("SetupDiGetDeviceRegistryPropertyW() failed, le = &#37;u",
                   GetLastError());
        }//if
 
        return false;
    }//if
 
    vector<wchar_t> vec_buff; // in case we have to go to the heap
    wchar_t auto_buff[512];
 
    DWORD buff_sz;
    wchar_t *buff;
    if (req_sz > sizeof(auto_buff))
    {
        vec_buff.reserve(req_sz/2 + 2);
        buff = &vec_buff[0];
        buff_sz = req_sz;
    }//if
    else
    {
        buff = auto_buff;
        buff_sz = sizeof(auto_buff);
    }//else
 
    res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                            0, (PBYTE)buff, buff_sz, 0);
    if (!res)
    {
        DWORD le = GetLastError();
        if (le != ERROR_INVALID_DATA)
        {
            printf("SetupDiGetDeviceRegistryPropertyW(%d) "
                   "failed, le = %u",
                   prop, le);
            return false;
        }//if
 
        // return empty string on ERROR_INVALID_DATA
        val.erase(val.begin(), val.end());
        return true;
    }//else
 
    val.assign(buff, req_sz);
    return true;
}//GetDeviceRegString
 
//------------------------------------------------------------------------------
 
template <typename T>
bool GetDeviceRegData(HDEVINFO infoSet, SP_DEVINFO_DATA *pinfoData,
                        DWORD prop, T &val)
{
    SetLastError(0);
    BOOL res = SetupDiGetDeviceRegistryPropertyW(infoSet, pinfoData, prop,
                                                 0, (PBYTE)&val,
                                                 sizeof(val), 0);
    DWORD le = GetLastError();
    if (!res || (le == ERROR_INVALID_DATA))
    {
        if (le != ERROR_INVALID_DATA)
            printf("GetDeviceRegData() failed, le = %u", le);
        return false;
    }//if
 
    return true;
}//GetDeviceRegData
 
//------------------------------------------------------------------------------
 
void ListDeviceClassData(const GUID *classGuid, std::list<DevData> &devList)
{
    devList.clear();
 
    const DWORD flags = DIGCF_PRESENT;
    HDEVINFO infoSet = SetupDiGetClassDevsW(classGuid, 0, 0, flags);
    if (infoSet == INVALID_HANDLE_VALUE)
    {
        printf("SetupDiGetClassDevs() failed, le = %u",
               GetLastError());
        return;
    }//if
 
    SP_DEVINFO_DATA infoData;
    infoData.cbSize = sizeof(SP_DEVINFO_DATA);
 
    DWORD n;
    for (n = 0; SetupDiEnumDeviceInfo(infoSet, n, &infoData); ++n)
    {
        DevData dd;
        if (GetDeviceRegString(infoSet, &infoData, SPDRP_DEVICEDESC,
                               dd.Description) &&
            GetDeviceRegData(infoSet, &infoData, SPDRP_DEVICE_POWER_DATA,
                             dd.PowerData))
        {
            devList.push_back(dd);
        }//if
    }//for
 
    if (GetLastError() != ERROR_NO_MORE_ITEMS)
    {
        printf("Last call to SetupDiEnumDeviceInfo(%d) failed, le = %u",
               n, GetLastError());
    }//if
 
    SetupDiDestroyDeviceInfoList(infoSet);
}//ListDeviceClassData
 
//------------------------------------------------------------------------------
 
void print_monitor_info()
{
    const GUID MonitorClassGuid =
        {0x4d36e96e, 0xe325, 0x11ce,
            {0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}};
     
    list<DevData> monitors;
    ListDeviceClassData(&MonitorClassGuid, monitors);
 
	stav_napajania = 0;
	printf("# Monitors = %d\n", monitors.size());
 
    list<DevData>::iterator it = monitors.begin(),
                            it_end = monitors.end();
    for (; it != it_end; ++it)
    {
        const char *off_msg = "";
 
        if (it->PowerData.PD_MostRecentPowerState > PowerDeviceD0)
            off_msg = ", *** Sleeping State ***";
 
        printf("[%ls]\n"
               "   PowerState = %d%s\n",
               it->Description.c_str(),
               it->PowerData.PD_MostRecentPowerState,
               off_msg);
		stav_napajania = it->PowerData.PD_MostRecentPowerState;
    }//for
     
    putchar('\n');
}//print_monitor_info
 
//------------------------------------------------------------------------------
 
int main()
{
	printf("\n\n*** Current Status of Monitor(s) ***\n\n");
    print_monitor_info();
	
	printf("\nEXIT CODE = %d \n", stav_napajania);

//  Sleep(3000);

//  printf("\n\n\n\n*** Turning OFF Monitor(s) ***\n\n");
//  fflush(stdout);
//  Sleep(500); // don't use mouse or keyboard
//  SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
//  Sleep(3000);
//  print_monitor_info();
//  Sleep(3000);

//  printf("\n\n\n\n*** Turning ON Monitor(s) ***\n\n");
//  SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
//  Sleep(3000);    
//	print_monitor_info();
//  Sleep(3000);

    return stav_napajania;
}//main
 
//------------------------------------------------------------------------------

s3n0
Příkazový řádek › VBS script pre zistenie stav…
6. 6. 2014   #190802

diky moc za snahu pomoct chlapi

nakoniec som nasiel cez Google po dalsich par hodinach hladania v C++ jazyku kod pre vypnutie alebo zapnutie monitora s tym, ze kod dokazal tiez nacitat aktualny "power saving" rezim monitora... vystupny kod 1 bol pri zapnutom monitore a iny kod pri "idle" monitoru... pri vypnutom monitore to bolo tusim kod cislo 4

-zdroj: http://cboard.cprogramming.com/…tection.html (hned druhy post)

nuz a skrz toto som si spravil nasledne v mojom .CMD scripte potrebne ukony... upravil som si C++ kod tak, aby bol exitcode z EXE-suboru po skompilovani prave stav zapnuteho/vypnuteho display-u a tento "return" kod v podstate precitam v .CMD scripte premennou %ERRORLEVEL%

kto by mal zaujem, tu je vlastne hotovy prekompilovany script do EXE podoby vcetne mojeho CMD scriptu, jedna sa vlastne o BUG v SpeedFan 4.49 na ATI kartach (-999 'C teplota GPU) a toto ma byt jeho docasne riesenie... ;)

http://www.bugtrack.almico.com/view.php?id=2120#bugnotes

http://uloz.to/xmxVEjbe/speedfan-ati-bug-2120-v2-zip

Příkazový řádek › xcopy a problém s CZ jménem…
5. 6. 2014   #190797

#1 paveljs
takze... ak tomu spravne rozumiem, ty potrebujes prekopirovat odkaz na spustanie konkretneho jedneho programu (.LNK subor) do automatickeho spustenia pri nastartovani Windows 7... sorry, ale tvoj dotaz je aspon pre mna dost neprehladny :P

nechapem presne ku akemu presne premenovaniu vlastne tam dochadza ? aky presne problem tam vznikol ? jak to chces mat ty vlastne ? a jak to funguje v skutocnosti ?

preco pouzivas zrovna prikaz "XCOPY" ved predsa ten sluzi pokial viem na kopirovanie vatsieho mnozstva suborov vcetne zloziek... existuje tiez jeho velmi dobra free alternativa pod nazvom "XXCOPY"... nuz teda preco nepouzivas klasicky prikaz pre kopirovanie suborov a teda prikaz "COPY" ?

a este jedna vec... ad cielova zlozka... skus kopirovat sem: (aspon tam mi nasiel TotalCommander aplikacie, ktore mam nastavene aj ja pri spusteni Windowsu, je to priama cesta cez "Roaming" a cez parameter aktualneho uzivatela %username%):

"C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"

Příkazový řádek › VBS script pre zistenie stav…
5. 6. 2014   #190796

Zdravim,

zhanam a nemozem najst uz asi 3 hodiny skrz Google nejaku obdobu scriptu najlepsie v podobe VBS (VisualBasicScript) alebo ako CMD/BATCH script (Windows/DOS command line). Jedna sa mi o zistenie stavu displayu, ze ci je zapnuty alebo vypnuty. Mozno by to slo riesit aj cez nacitavanie power managmentu, ale nic co som nasiel alebo skusil nefungovalo pripadne stav bol stale ten isty (monitor bol akoze zapnuty, aj ked ho uz vyplo skrz Windows usporny rezim po jednej predvolenej minute). Potrebujem to z dovodu toho, ze nemenovana aplikacia ma problem pri spusteni vypnuteho LCD monitoru :) kludne by pomohla aj nejaka mini utilitka, ktora by vraciala na vystupe z5tne do CMD/BATCH suboru nejaky ten "ERRORLEVEL" o stave zapnuteho ci vypnuteho monitoru. Potrebujem to pre Windows-7.

Diky.

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý