Autor Beitrag
El Presidente
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 14.08.07 16:59 
Is there a possiblity to turn off disks with code?Disk type does not matter..
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 14.08.07 17:05 
you mean the hard disks? CD? or what are you talking about?
you know there's great difference - I don't really think you can "turn off" (could you also describe what you mean by turn off? ) the hard disk, this could cause the computer to crash, I guess.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
El Presidente Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 14.08.07 17:11 
Nono i mean like a hard drive shutdown like that power managment does it,if you dont use some disk after some time it shuts it down.
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 14.08.07 18:10 
Welcome, RAZOR!

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
Type  
TIDERegs = packed record 
    bFeaturesReg     : Byte; // Used for specifying SMART "commands". 
    bSectorCountReg  : Byte; // IDE sector count register 
    bSectorNumberReg : Byte; // IDE sector number register 
    bCylLowReg       : Byte; // IDE low order cylinder value 
    bCylHighReg      : Byte; // IDE high order cylinder value 
    bDriveHeadReg    : Byte; // IDE drive/head register 
    bCommandReg      : Byte; // Actual IDE command. 
    bReserved        : Byte; // reserved for future use.  Must be zero. 
  end
  IDEREGS   = TIDERegs; 
  PIDERegs  = ^TIDERegs; 

TIdSector = packed record 
    wGenConfig                 : Word; //00 
    wNumCyls                   : Word; 
    wReserved                  : Word; 
    wNumHeads                  : Word; 
    wBytesPerTrack             : Word; 
    wBytesPerSector            : Word; 
    wSectorsPerTrack           : Word; 
    wVendorUnique              : Array[0..2of Word; 
    sSerialNumber              : Array[0..19of Char; //10-19 
    wBufferType                : Word; 
    wBufferSize                : Word; 
    wECCSize                   : Word; 
    sFirmwareRev               : Array[0..7of Char;  //23-26 
    sModelNumber               : Array[0..39of Char; //27-46 
    wMoreVendorUnique          : Word; 
    wDoubleWordIO              : Word; 
    wCapabilities              : Word; 
    wReserved1                 : Word; 
    wPIOTiming                 : Word; 
    wDMATiming                 : Word; 
    wBS                        : Word; 
    wNumCurrentCyls            : Word; 
    wNumCurrentHeads           : Word; 
    wNumCurrentSectorsPerTrack : Word; 
    ulCurrentSectorCapacity    : ULONG; //57-58 
    wMultSectorStuff           : Word; 
    ulTotalAddressableSectors  : ULONG; //60-61 
    wSingleWordDMA             : Word; 
    wMultiWordDMA              : Word;  //63 
    wFlowControlPIOSupported   : Word;  //64 
    wMinimumMultiWordDMA       : Word;  //65 
    wRecommendedMultiWordDMA   : Word;  //66 
    wMinimumPIOCycleWOFlow     : Word;  //67 
    wMinimumPIOCycleIORDYFlow  : Word;  //68 
    bReserved1                 : Array[0..21of Byte; //69-79 
    wMajorVersionNumber        : Word;  //80 
    wMinorVersionNumber        : Word;  //81 
    wCommandSetSupported       : Word;  //82 
    wCommandSetSupported2      : Word;  //83 
    wCommandSetExtension       : Word;  //84 
    wCommandSetFeatureEnabled1 : Word;  //85 
    wCommandSetFeatureEnabled2 : Word;  //86 
    wCommandSetFeatureEnabled3 : Word;  //87 
    wUltraDMAMode              : Word;  //88 
    wTimeRequiredErase         : Word;  //89 
    wTimeRequiredEnhancedErase : Word;  //90 
    wAbleMode                  : Word;  //91 
    bReserved2                 : Array[0..71of Byte; //92-127 
    wSecurityModeFeature       : Word;  //128 
    wCurrentFeatureOption      : Word;  //129 
    wReserved2                 : Word;  //130 
    wInitialPowerMode          : Word;  //131 
    bReserved3                 : Array[0..247of Byte; //132-255 
  end
  PIdSector = ^TIdSector;

const 
  BufferSize = SizeOf(TIDERegs)+4
  IOCTL_IDE_PASS_THROUGH        = $0004d028;


implementation

{$R *.dfm}

Function IdeRegPassThrough(Device: Stringvar ideregs: TIDERegs ): Boolean; 
var 
  ret:BOOL; 
  hDevice : THandle; 
  cbBytesReturned : DWORD; 
  pInData : PIDERegs; 
  pOutData : Pointer; 
  Buffer : Array[0..BufferSize-1of Byte; 
begin 
  Result := False; 
  FillChar(Buffer,BufferSize,#0); 

  hDevice := CreateFile( PChar(Device), GENERIC_READ or GENERIC_WRITE, 
    FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 00 ); 
  if hDevice=INVALID_HANDLE_VALUE then Exit; 
  try 
    pInData := @Buffer; 
     pOutData := pInData; 
    pInData^ := ideregs; 
    ret := DeviceIoControl( hDevice, IOCTL_IDE_PASS_THROUGH, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ); 
    if not ret then begin 
      Exit; 
    end
    ideregs := PIDERegs(pOutData)^; 
  finally 
    CloseHandle(hDevice); 
  end
  Result := True; 
end


function SendToSleep(Device: String): Boolean;
var 
  ideregs : TIDERegs; 
begin 
  Result := False; 
  with ideregs do 
  begin 
    bFeaturesReg     := 0
    bSectorCountReg  := 0
    bSectorNumberReg := 0
    bCylLowReg       := 0
    bCylHighReg      := 0
    bDriveHeadReg    := $A0
    bCommandReg      := $E6
    bReserved        := 0
  end
  if not IdeRegPassThrough(Device, ideregs ) then Exit else Result := True; 
end;

//Label1.caption:= BoolToStr(SendToSleep('\\.\PhysicalDrive0'));
El Presidente Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 14.08.07 18:22 
lolz!


Thank you for the code now i have to test it so i dont have to listen to my noisy disk anymore XD.
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Di 14.08.07 21:51 
Könnte ich dafür vielleicht eine deutsche Erklärung bekommen? Mein Englisch ist nicht gerade das Beste. :oops:
El Presidente Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 14.08.07 22:45 
I really dont understand this function... :oops:

Function IdeRegPassThrough(Device: String; var ideregs: TIDERegs ): Boolean;


I did it like this


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm1.Button1Click(Sender: TObject);
var ideregs: TIDERegs;

begin

 IdeRegPassThrough('PhysicalDrive0',       but what goes in here                 );
SendToSleep('PhysicalDrive0');
end;

I guess something of these?e



Type    
TIDERegs = packed record
    bFeaturesReg     : Byte; // Used for specifying SMART "commands".
    bSectorCountReg  : Byte; // IDE sector count register
    bSectorNumberReg : Byte; // IDE sector number register
    bCylLowReg       : Byte; // IDE low order cylinder value
    bCylHighReg      : Byte; // IDE high order cylinder value
    bDriveHeadReg    : Byte; // IDE drive/head register
    bCommandReg      : Byte; // Actual IDE command.
    bReserved        : Byte; // reserved for future use.  Must be zero.
  end;
  IDEREGS   = TIDERegs;
  PIDERegs  = ^TIDERegs;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19327
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 15.08.07 04:14 
A little hint:
Have a look at the function SendToSleep ;-). There you see a call to the other function and how to do it.
The parameter is not for passing information TO the function but to GET some back from it. So it is declared as var parameter and before the function call you should initialize the variable of type TIDERegs before you pass it to IdeRegPassThrough. That's it.